I often use * to highlight all instances of the current word, and the fact that it advances to the next word is pretty annoying. I'd like to disable this beh开发者_开发技巧avior, knowing that I can always use "n" if I actually need to advance.
Any insight?
EDIT: I should add that I'd like to avoid a screen redraw at all costs as it is visually distracting.
Try this:
nnoremap * :let @/ = "\\<<C-R><C-W>\\>"<CR>
(Assumes you have 'hlsearch'
on). This just changes the current search pattern to the word under the cursor (surrounded by \<
and \>
to match word boundaries). If you have hlsearch
enabled, it will highlight the word. n
and N
will then work as normal.
See:
:help :let-@
:help quote/
:help c_CTRL-R_CTRL-W
Try this Vim Tip. I find it very useful. The most interesting is that you can have more matches and every one in different color.
I cannot give an exact answer, but this Vim Tip tells you what you have to add to your .vimrc
to simply highlight the word under the cursor when Vim is in idle state.
Works without any key-remapping...
You can remap it to return:
nnoremap * '*N'
(but this redraws the screen)
精彩评论