Emacs样式高亮显示,用于Vim中的增量搜索 [英] Emacs style highlighting for incremental search in vim

查看:94
本文介绍了Emacs样式高亮显示,用于Vim中的增量搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Vim中,有没有一种方法可以在搜索时对所有所有匹配进行即时突出显示?

In Vim, is there a way to enable on-the-fly highlighting for all matches when searching?

如果启用incsearch并键入"/something",它将仅突出显示第一个匹配项.如果启用hlsearch并键入"/something",则在按Enter键之前,什么都不会发生(它仅突出显示先前的搜索).

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).

在emacs中,第一个匹配项将突出显示,并且(稍有延迟)所有其他匹配项将以不同的颜色突出显示,从而在扫描一段代码中的匹配项时几乎立即获得反馈.

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.

推荐答案

不回答您的问题,但可能此Wikia帖子可以提供帮助吗?

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

该帖的引用:

将以下代码放入您的vimrc中,或创建文件 〜/.vim/plugin/autohighlight.vim(Unix)或 $ HOME/vimfiles/plugin/autohighlight.vim(Windows)包含 下面的脚本.然后重新启动Vim.

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.

要自动突出显示当前单词,请键入z/.把关掉, 再次输入z/.

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

这篇关于Emacs样式高亮显示,用于Vim中的增量搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆