Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search highlighting (hlsearch) not working in vim

Tags:

vim

I have a problem with search highlighting in vim. I have used it before but currently it does not work at all.

  • I have entered :set hlsearch, which is also in my .vimrc file.
  • I have entered :set hlsearch? and the result is hlsearch, indicating that I have successfully turned the option on. (right?)
  • I am running vim and not vi, so that is not the problem.
  • I have searched around but only found people asking about turning OFF search highlighting.

I would appreciate any input as this has been driving me nuts. Thanks!

Edit: highlighting also doesn't work for spellcheck, so evidently it's something global about highlighting.

like image 291
Carl Smith Avatar asked Mar 21 '13 22:03

Carl Smith


People also ask

How to highlight a search in Vim?

Add set hlsearch in the file. Save the file. Now your search will always be highlighted in vim. For single time use, just use :set hlsearch in vim, which will be in effect for that instance only. how to remove that highlight once i have found out the matches? i pressed escape and the highlight still exists.

How do I highlight all matches in a search?

To highlight all search matches, set the following option: With the defaults, setting this option causes all text matching the current search to be highlighted using the Search highlight group, which adds a yellow background to the current highlighting. See :help hl-Search, or type :hi Search to see what color you have it set to.

How to remove the highlight(s) from a search?

For those who are looking to remove the highlight (s), according to :help hlsearch, just type :nohlsearch. Your next search will still get highlighted.

How do I change the color of my HL-search?

See :help hl-Search, or type :hi Search to see what color you have it set to. You can easily change the default highlighting with, for example, :hi Search guibg=LightBlue . To disable the highlighting temporarily, enter (this is a command, not an option):


1 Answers

When you have problems with multiple highlightings (like search and spell in your case), first check the defined highlightings with

:hi

If any groups are wrong or off, check your :colorscheme, and maybe try another.

In the console, color problems are often related to the number of available colors, a hairy problem. Check with

:set t_Co?

Another good tool for checking problems with individual syntax items is the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin.

like image 74
Ingo Karkat Avatar answered Sep 20 '22 12:09

Ingo Karkat