vim - Clear search highlight on autocmd BufWrite -
i tried of suggestions in 3 questions:
get rid of vim's highlight after searching text
how rid of search highlight in vim
vim clear last search highlighting
it's :noh
, , works when type manually. want happen on bufwrite, tried multiple ways, none of worked:
function! removehighlight() :noh endfunction autocmd bufwrite * :call removehighlight() autocmd bufwrite * :noh autocmd bufwrite * :execute "normal! :noh\<cr>"
debuging echom
s , adebug\<esc>
in function , in third autocmd show execute successfully, :noh
has no effect.
(also tried :let @/ = ""
worked clears search pattern, not i'm looking for. want rid of highlight til pressing n
or similar)
using bufwritepost
doesn't have effect, either.
it workaround can set nohlsearch
autocmd. can add mapping set n , n.
au bufwrite * set nohlsearch nnoremap <silent> n n:set hlsearch<cr> nnoremap <silent> n n:set hlsearch<cr>
or maybe better, check if set
au bufwrite * set nohlsearch nnoremap <silent> n n:call togglehlback()<cr> nnoremap <silent> n n:call togglehlback()<cr> function! togglehlback() if &hlsearch == 'nohlsearch' set hlsearch endif endfunction
Comments
Post a Comment