Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight search words in vim permanently?

Tags:

vim

I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs.

I always have to use :se hlsearch to highlight the search keyword.

So, I want the solution that it should set command permanently, and I should not use the command always when vim starts.

like image 286
Swapnil Kale Avatar asked Aug 05 '14 10:08

Swapnil Kale


People also ask

How do I enable highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.


2 Answers

Set the command in .vimrc.

Use the following commands:

  1. Open ~/.vimrc file (or create it if it didn't exist).
  2. Add set hlsearch in the file.
  3. 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.

like image 118
Swapnil Kale Avatar answered Sep 19 '22 15:09

Swapnil Kale


If you want to highlight multiple searches (in parallel, with different colors), check out my Mark plugin; it also allows to persist the highlightings across Vim sessions through the viminfo file; cp. :help mark-persistence.

like image 31
Ingo Karkat Avatar answered Sep 18 '22 15:09

Ingo Karkat