Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: automatically highlight all occurences of selected word [duplicate]

Tags:

vim

Notepad++ has this really neat feature that if you select one word, every other occurence of the word is automatically highlighted, like this (only the first autocmd is highlighted by me):

N++ highlighting screenshot

I am aware that a similar thing has already been asked, but I am hoping that there is a solution which does not require manual interaction.

like image 601
Nicolas Avatar asked Nov 30 '22 12:11

Nicolas


1 Answers

If you press * Vim will search for all occurrences of the word under the cursor.

If you have search highlighting turned on, they will be highlighted.

You can turn on search highlighting by putting this in your .vimrc:

set hlsearch

One nice plus is you don't have to select the word anymore... you just hit the * key.

(you could map it to another key to make it even more convenient)


If you don't like the way the cursor moves when you press * you can prevent it with a simple mapping:

nnoremap * *N

(put it in your .vimrc)

This keeps the cursor in its current position when you press *.

like image 97
12 revs Avatar answered Dec 04 '22 23:12

12 revs