Highlight all occurrence of a selected word?

后端 未结 15 1677
难免孤独
难免孤独 2020-12-12 10:05

How can I highlight all occurrence of a selected word in GVim, like in Notepad++?

15条回答
  •  天涯浪人
    2020-12-12 10:23

    I know than it's a really old question, but if someone is interested in this feature, can check this code http://vim.wikia.com/wiki/Auto_highlight_current_word_when_idle

    " Highlight all instances of word under cursor, when idle.
    " Useful when studying strange source code.
    " Type z/ to toggle highlighting on/off.
    nnoremap z/ :if AutoHighlightToggle()set hlsendif
    function! AutoHighlightToggle()
       let @/ = ''
       if exists('#auto_highlight')
         au! auto_highlight
         augroup! auto_highlight
         setl updatetime=4000
         echo 'Highlight current word: off'
         return 0
      else
        augroup auto_highlight
        au!
        au CursorHold * let @/ = '\V\<'.escape(expand(''), '\').'\>'
        augroup end
        setl updatetime=500
        echo 'Highlight current word: ON'
      return 1
     endif
    endfunction
    

提交回复
热议问题