I’ve got a file (LaTeX) which contains lines I wish to comment out.
The regex that I use after visually-selecting the relevant block is :s/^/%/g, which works fine. However, vim then highlights every matching occurrence of the first part of the regular expression used in the replace, (highlights the first character on the beginning of every line).
The selection changes if I do another search, or another search-and-replace, but I can’t work out how to turn it off without doing a ‘useless’ search.
It’s particularly annoying if I search for whitespace (because having every ‘‘ highlighted in a text file is visually annoying).
How do I de-select the matching strings after the search-and-replace has been completed?
:nohlsearchwill stop highlighting it but keep it as the active search pattern. (It will start being highlighted onnetc.):let @/=""will clear the search pattern register (so thatnetc. won’t work).A common thing I’ve seen in Vim is
map <Leader><Space> :noh<CR>; this has the result that (assuming the default leader, backslash) \Space will stop highlighting the current match.