I currently am using this to function like in Geany (my old editor) when I select text and press F3:
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
Of course this is * for search forward for selected text and # for backward search of selected text.
What I can’t figure out is how to get both of these to re-select the found word (or whatever is selected) once it find’s it so I can continue to press * or # for continued search. So I don’t have to re-select what it find’s if that’s not what I want and want to continue searching.
Your solution of adding
v//e<CR>works, but it has the side effect of making the search to the end, which affects other commands liken/N. A better option is to re-establish the previous selection at the current position via1v(or1vlwhen'selection'isexclusive).