例如,我们的文字是:
hello world
abcd hello world
hello world
在eclipse中,当光标位于某个单词上时,该单词hello
将在当前文件中自动突出显示。当您ww
在普通模式下键入时,光标位于其他单词world
上将在当前文件中突出显示,该hello
标记将自动取消突出显示。此功能对用户来说非常方便。
vim是否可以通过某些插件来实现?
vim.wikia.com上有一个脚本可以做到这一点。它会一直等到您停止移动光标,然后突出显示当前单词的所有实例。然后n
,您可以N
像平常使用搜索结果一样使用和在它们之间跳转。
我将其复制到此处,以防链接断开:
" 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
如该页面的注释中所述,如果您始终希望启用此功能,则可以vimrc
在定义该功能后从其调用。这样,您可以使用z/
(或分配给它的任何快捷方式)稍后再次将其关闭。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句