diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/insert_suspend_hlsearch.vim | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/plugin/insert_suspend_hlsearch.vim b/plugin/insert_suspend_hlsearch.vim index 5dd1e74..5d199f7 100644 --- a/plugin/insert_suspend_hlsearch.vim +++ b/plugin/insert_suspend_hlsearch.vim @@ -14,10 +14,31 @@ if !has('autocmd') || !has('extra_search') || v:version < 700 endif let g:loaded_insert_suspend_hlsearch = 1 +" Initialise option saving variable +let s:hlsearch_save = &hlsearch + +" Save the current value of the 'hlsearch' option in a script variable, and +" disable it if enabled. Note that :nohlsearch does not work for this; see +" :help autocmd-searchpat. +function! s:Suspend() abort + let s:hlsearch_save = &hlsearch + if &hlsearch + set nohlsearch + endif +endfunction + +" Restore the value of 'hlsearch' from the last time s:HlsearchSuspend was +" called. +function! s:Restore() abort + if !&hlsearch && s:hlsearch_save + set hlsearch + endif +endfunction + " Clear search highlighting as soon as I enter insert mode, and restore it " once left augroup insert_suspend_hlsearch autocmd! - autocmd InsertEnter * call insert_suspend_hlsearch#Suspend() - autocmd InsertLeave * call insert_suspend_hlsearch#Restore() + autocmd InsertEnter * call s:Suspend() + autocmd InsertLeave * call s:Restore() augroup END |