I noticed that when I use
:nohlsearch that it does not actually do the same thing as
In particular, the
hlsearch setting is not actually switched off (which is what
:set hlsearch) accomplishes.
To demonstrate what I mean:
:set hlsearch :nohlsearch :echo &hlsearch
1 (hlsearch is still set!)
:set hlsearch :set nohlsearch :echo &hlsearch
0 because we switched hlsearch off using the standard way to switch a setting off in vim.
So I'm sort of wondering because there has to be some actual reason for the
:nohlsearch ex command to exist.
The reason why I care is that I now have a need in my vim scripting to test whether the search highlight is active, and since I was using
:nohlsearch instead of ":set nohlsearch" in my other scripting, my
&hlsearch test always returns
1. So I am wondering what I'm changing by no longer using the
nohlsearch ex command.