Swapnil Kale
Swapnil Kale

Reputation: 3040

How to highlight search words in vim permanently?

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.

Upvotes: 74

Views: 92159

Answers (4)

Rich
Rich

Reputation: 303

My SelX plugin allows you to highlight and search for many different things at once on a per-tab basis, with different colours. The highlight config can be saved to a vim session

https://www.vim.org/scripts/script.php?script_id=5875

Upvotes: 0

Swapnil Kale
Swapnil Kale

Reputation: 3040

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.

Upvotes: 125

Tinmarino
Tinmarino

Reputation: 4041

For those wanting to visually keep highlighted their search:

:syn match stupid "ctrl + /"

:hi stupid ctermbg=Red guibg=Red

Explanation:

The first line add your regex to a syntax type called "stupid" (note that ctrl + / means you must press ctrl+R then / to get the content of the search registry).

The second line gives a red color to the "stupid" syntax regex.

Upvotes: 4

Ingo Karkat
Ingo Karkat

Reputation: 172570

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.

Upvotes: 7

Related Questions