Deselecting appropriate strings after searching and replacing in Vim

I have a file (LaTeX) that contains the lines that I want to comment on.
The regular expression that I use after visually selecting the appropriate block :s/^/%/gworks fine. However, vim then highlights each matching occurrence of the first part of the regular expression used in replace (highlights the first character at the beginning of each line).

The choice changes if I do another search or another search and replace, but I cannot decide how to turn it off without doing a β€œuseless” search.

This is especially annoying if I'm looking for spaces (because having every " " highlighted in a text file is visually annoying).

How to deselect suitable rows after completing the search and replace?

+3
source share
4 answers

:nohlsearchwill stop highlighting it, but save it as an active search template. (It will start to highlight on n, etc.)

:let @/=""will clear the search pattern register (so that netc. will not work).

The usual thing I saw in Vim is map <Leader><Space> :noh<CR>; this leads to the fact that (assuming the default leader, the backslash) \ Spacestops highlighting the current match.

+7
source

:nohlsearchwill remove the selection from the current search. The backlight will return to the next search.

:set nohlsearch will disable highlighting for the current vim session.

If you want to completely disable the selection, add :set nohlsearchto your.vimrc

+4
source

, :

/poop 
+3

vimrc, - <, > + enter,

     map <silent> <leader><cr> :noh<cr>
-1
source

All Articles