Search code examples
vimnetbeanshighlight

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?


Solution

  • 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