Add word under cursor to search pattern

后端 未结 2 1439
一整个雨季
一整个雨季 2021-02-12 18:03

Using * when the cursor is on a word theWord, vim directly jumps to the next appearance of exactly that word, i.e. performes /\\

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 18:25

    Try

    :nnoremap  + :let @/ .= '\\|\<'.expand('').'\>'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  + :let @/ .= '\\|'.escape(lh#visual#selection(), '/\^$*.[~')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.

提交回复
热议问题