像在NetBeans中一样,在Vim中的光标下方突出显示变量 [英] Highlight variable under cursor in Vim like in NetBeans

查看:115
本文介绍了像在NetBeans中一样,在Vim中的光标下方突出显示变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NetBeans中工作,喜欢这个功能:当您将光标放在变量名中时,所有出现的变量都会突出显示.这对于快速搜索所有出现的变量非常有用.可以将这种行为添加到Vim吗?

I worked in NetBeans and liked this feature: when you place cursor in a variable name all occurences of the variable are highlighted. This is very useful for quick searching all occurences of the variable. Is it possible to add this behavior to Vim?

推荐答案

此自动命令将执行您想要的操作:

This autocommand will do what you want:

:autocmd CursorMoved * exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\'))

在示例中,我使用了IncSearch高亮组,但是您可以通过运行以下命令找到其他要使用的颜色:

I have used the IncSearch highlight group in my example, but you can find other colours to use by running this command:

:so $VIMRUNTIME/syntax/hitest.vim

这篇关于像在NetBeans中一样,在Vim中的光标下方突出显示变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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