Reputation: 121961
I am aware that it is possible to configure vim to highlight all matches for the searched word.
But, is it possible to highlight the entire line(s) on which the searched for word is found? If so, how?
Upvotes: 5
Views: 6197
Reputation: 385
You may install this plugin highlight.vim. One of the shortcut key <C-h><C-j>
allowed you to highlight the line contains the previous search pattern.
Upvotes: 0
Reputation: 196456
The exact solution depends probably on your goal:
Do you want to make the matched lines stand out a little more?
Do you want to know the line numbers for further use?
Do you want to act directly on those lines?
You could use the quickfix window to list the lines containing a match:
:vim! foo . | copen
You could use the :global
command to list or act on every line containing a match:
:g/foo<CR> " list the lines
:g/foo/<Ex command> " act on each line
Upvotes: 5
Reputation: 172510
If you generally want the current line highlighted:
:set cursorline
If you just want the searches highlighted, the only easy way is by extending the search pattern to cover the entire line:
:set hlsearch
:let @/ = '.*'.@/.'.*'
Note that on n
/ N
, the cursor will now jump to the beginning of the line, not the matched word. Also, you won't be able to do :%s//...
substitutions of the matched word (without repeating the search pattern) any more.
Upvotes: 11
Reputation: 272217
:set hlsearch
will highlight the searched-for word.
Note also that you can highlight your current line i.e. the line your cursor is on. So when you move between matches, the complete line you move to will be highlighted.
Upvotes: 3
Reputation: 3998
Please use this:
To highlight all the search pattern matches in a file set the following option:
:set hlsearch
To disable the highlighting temporarily, use:
:nohlsearch
Upvotes: -1