Vim: search and highlight but do not jump

后端 未结 12 2145
一生所求
一生所求 2020-12-02 18:02

The super star (*) key in Vim will search for the word under the cursor and jump forward to the next match. The user can jump to the next matches with the n key.

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 18:49

    I have the following in my .vimrc, which I think works better than the other alternatives:

    " Put word under cursor into search register and highlight
    nnoremap  * :let @/='\<=expand("")\>':set hls
    vnoremap  * :
      \let old_reg=getreg('"')let old_regtype=getregtype('"')
      \gvy:let @/=substitute(
      \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')
      \gV:call setreg('"', old_reg, old_regtype):set hls
    

提交回复
热议问题