Is there a way to prevent cursor to search forward when using the
I just want to highlight the word I am on & others, but not move to forward nor backward.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
This will do for the
* search, I'm not sure how to do that for
nnoremap <silent> * :let @/= '\<' . expand('<cword>') . '\>' <bar> set hls <cr>
@/ is the search register, which we set to
<cword>, the word under the cursor, surrounded by words boundaries
\> to match actual words rather than parts of words.
g* matches even "non words". We can adapt it as well :
nnoremap <silent> g* :let @/=expand('<cword>') <bar> set hls <cr>
For visual mode:
vnoremap * y/\V<C-R>=escape(@",'/\')<CR><CR>
This copies the selection into the unnamed register
:h registers), starts a search with its content, backslashes escaped, via the
:h expression register (inserted with