开发者

Emacs style highlighting for incremental search in vim

开发者 https://www.devze.com 2023-02-06 08:39 出处:网络
In Vim, is there a way to enable on-the-fly highlighting for all matches when search开发者_如何学Cing?

In Vim, is there a way to enable on-the-fly highlighting for all matches when search开发者_如何学Cing?

If I enable incsearch and type "/something" it will highlight the first match only. If I enable hlsearch and type "/something", nothing happens until I press enter (it only highlights the previous search).

In emacs the first match will be highlighted, and (after a slight delay) all other matches on the screen are highlighted in a different color, giving almost instant feedback when scanning for matches in a piece of code.


Doesn't answer your question, but maybe this Wikia post can help?

Quote from that post:

Put the following code in your vimrc, or create file ~/.vim/plugin/autohighlight.vim (Unix) or $HOME/vimfiles/plugin/autohighlight.vim (Windows) containing the script below. Then restart Vim.

To automatically highlight the current word, type z/. To turn off, type z/ again.

" 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()<Bar>set hls<Bar>endif<CR>
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('<cword>'), '\').'\>'
    augroup end
    setl updatetime=500
    echo 'Highlight current word: ON'
    return 1
  endif
endfunction


Add this to your .vimrc

hi Search guifg=black guibg=#C6C5FE gui=BOLD ctermfg=black ctermbg=cyan cterm=BOLD

Of course, you might want to change the colors to suit your needs.

0

精彩评论

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

关注公众号