I tried most of the suggestions in those three questions:
Get rid of Vim's highlight after searching text
How to get rid of search highlight in Vim
Vim clear last search highlighting
It's mainly the :noh
, and it works when I type it manually. I just want it happen on BufWrite, so I tried multiple ways, none of which worked:
function! RemoveHighLight()
:noh
endfunction
autocmd BufWrite * :call RemoveHighLight()
autocmd BufWrite * :noh
autocmd BufWrite * :execute "normal! :noh\<cr>"
Debuging echom
s and adebug\<esc>
in the function and in the third autocmd show that they execute successfully, just the :noh
has no effect.
(Also tried :let @/ = ""
which worked but it clears the search pattern, which is not I'm looking for. I just want to get rid of the highlight til pressing n
or similar)
Using BufWritePost
doesn't have effect, either.