Using * when the cursor is on a word theWord, vim directly jumps to the next appearance of exactly that word, i.e. performes /\<theWord\>.
Questions:
Is there a way to add another word otherWord to the search, when the cursor is on this other word, such that one performes /\<theWord\>\|\<otherWord\>?
Try something like:
:let @/=@/.'\|\<'.expand("<cword>").'\>' this appends to the previous search pattern the current word under the cursor) with some delimiters (\| and the word boundaries...)nnoremap <F4> :let @/.='\\|\<'.expand("<cword>").'\>'<CR>
Try
:nnoremap <silent> + :let @/ .= '\\|\<'.expand('<cword>').'\>'<cr>n
That will append the word under the cursor to the search register when '+' is hit, and jump to the next occurrence of any searched pattern.
If you wish to extend it to the visual mode, (as it could be done to n_star), you have
:vnoremap <silent> + <c-\><c-n>:let @/ .= '\\|'.escape(lh#visual#selection(), '/\^$*.[~')<cr>n
With lh#visual#selection() to fetch the current selection, and escape() to neutralize some active characters in regexes. v_CTRL-\_CTRL-N being a safe and silent escape sequence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With