Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight variable under cursor in Vim like in NetBeans

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?

like image 735
kipelovets Avatar asked Oct 11 '09 17:10

kipelovets


People also ask

How do I highlight a variable in Vim?

vimrc file by using vim editor. Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open .

How do I highlight a cursor in Vim?

With the default backslash leader key, pressing \l will highlight the line that currently contains the cursor. The mapping also sets mark l so you can type 'l to return to the highlighted line.

How do you highlight in vi?

To enable Syntax Highlighting feature in VI editor, open the file called /etc/profile. Add the alias function to VI by pointing to VIM in /etc/profile file. This file is used to set alias functions globally. If you would like to set user specific aliases and functions, then you need to open the file .


1 Answers

This autocommand will do what you want:

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

vi highlight current word

Edit: 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 
like image 56
too much php Avatar answered Sep 29 '22 07:09

too much php