views:

118

answers:

7

How can I highlight all occurrence of a selected word in gvim? (like notepad++..)

+1  A: 

The * key will highlight all occurrences of the word that is under the cursor.

sleepynate
wilhelmtell
+1  A: 
set hlsearch

maybe ?

ldigas
+6  A: 

In Normal mode:

:set hlsearch

Then search for a pattern with the command / in Normal mode, or <Ctrl>o followed by / in Insert mode. * in Normal mode will search for the next occurrence of the word under the cursor. The hlsearch option will highlight all of them if set. # will search for the previous occurrence of the word.

To remove the highlight of the previous search:

:nohlsearch

You might wish to map :nohlsearch<CR> to some convenient key.

wilhelmtell
If you plan on toggling `hlsearch` a lot you might want to map `:set hlsearch!` instead of `:set nohlsearch`. This toggles the setting rather than always turning it off.
David Winslow
+1  A: 

Enable search highlighting:

:set hlsearch

Then search for the word:

/word<Enter>
John Kugelman
+1  A: 

First (or in your .vimrc):

:set hlsearch

Then position your cursor over the word you want highlighted, and hit *.

hlsearch means highlight all occurrences of the current search, and * means search for the word under the cursor.

Ned Batchelder
+1  A: 

First ensure that hlsearch is enabled by issuing the following command

:set hlsearch

You can also add this to your .vimrc file as set

set hlsearch

now when you use the quick search mechanism in command mode or a regular search command, all results will be highlighted. To move forward between results, press 'n' to move backwards press 'N'

In normal mode, to perform a quick search for the word under the cursor and to jump to the next occurrence in one command press '*', you can also search for the word under the cursor and move to the previous occurrence by pressing '#'

In normal mode, quick search can also be invoked with the

/searchterm<Enter>

to remove highlights on ocuurences use, I have bound this to a shortcut in my .vimrc

:nohl
kashif
A: 

My favorite for doing this is the mark.vim plugin. It allows to highlight several words in different colors simultaneously.

Example Screenshot

Habi