开发者

In vim, is there a way to rebind "*" to highlight the current word, without advancing to the next? [duplicate]

开发者 https://www.devze.com 2023-02-14 20:12 出处:网络
This question already has answers here: Vim: search and highlight but do not jump (14 answers) Closed 4 years ago.
This question already has answers here: Vim: search and highlight but do not jump (14 answers) Closed 4 years ago.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消