'hlsearch' is very useful but at the same time too intrusive.
Help topic states specifically that :nohlsearch
doesn't work in autocommand (actually it also doesn't work in timer callbacks) so there is no obvious way to make it auto turned off.
There is vim-cool plugin by @romainl and the essense of it might be the following snippet I am currently using:
# turn off hlsearch after:
# - doing nothing for 'updatetime'
# - getting into insert mode
augroup auto_nohlsearch | au!
set updatetime=2000
noremap <Plug>(nohlsearch) <cmd>nohlsearch<cr>
noremap! <expr> <Plug>(nohlsearch) execute('nohlsearch')[-1]
au CursorHold * call feedkeys("\<Plug>(nohlsearch)", 'm')
au InsertEnter * call feedkeys("\<Plug>(nohlsearch)", 'm')
augroup END
Should we add this example, even though it is "hackish", to the help topic right after :h :nohlsearch
or maybe even a simple plugin in the same way comment
was added?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
The doc is riddled with "hackish" examples like this so why not one more? I find the idea of adding a small plugin better, though. MacVim releases are lagging a bit so I didn't have a chance to play with your commenting plugin yet but it definitely looks like the way to go.
FWIW, vim-cool was a pretty successful attempt to solve one of my pet peeves with hlsearch
: that it lingers on after it stopped being relevant. Whether it is through a built-in plugin, a snippet in the doc, a third-party plugin, or in the core, the problem can be considered solved at this point and, as such, doesn't deserve much attention.
But that still leaves the other one: that the highlighting affects all windows, for which there is no workaround AFAIK. If some effort can be made to improve hlsearch
, I think that's where it would be most useful.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
There is an entry in todo.txt to make 'hlsearch' global/local option. I remember I spent some time several years ago looking into it (but at least back then it wasn't that simple, but I forgot details).
Regarding @habamax request, does it make sense to add this (and possibly also the highlight-yank implementation from the help page) into the vim-scripts library. Not sure if we would be littering the library and if this is a particular good idea or rather a bad one 🤷
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I am not sure about library (don't know the purpose of it) but having packadd autonohlsearch
should be easy enough to use.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
(mostly for Neovim compatability)
Sigh…
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
alright then can you make this a real PR then please? Please don't forget a bit of documentation and also please leave adjusting 'updatetime' option value alone.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Closed #15039 as completed via 26de90c.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I have something similar in my config, but I prefer 10 sec delay, and also have <esc>
do nohls
in addition. Maybe you can make the timeout configurable by using autocmd CursorHold * timer_start(timeout - &ut, (_) => feedkeys("\<plug>(nohlsearch)", 'm'))
.
I also prefer keeping highlights in insert mode as I replace some highlighted fragments (for instance).
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
One other note: if hlsearch is made global/local, I’d prefer the default to stay as is (it’s remarkably useful when looking at commit diffs + an open buffer to quickly highlight long function names in all windows, for example).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Maybe you can make the timeout configurable by using
autocmd CursorHold * timer_start(timeout - &ut, (_) => feedkeys("\<plug>(nohlsearch)", 'm'))
.
Wouldn't it trigger if after updatetime but before additional timeout there would be cursor movement? And what if at that time I will search for another thing? Say if there is 6 seconds of additional timeout, I theoretically can do another search which would be "unhighlighted" almost right away. Not sure though.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.