From 6e626e4f4b969480495a72ce94599be8c85351f6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 17 Jun 2018 15:47:58 +1200 Subject: Use autoload since we have Vim >= 7.0 --- autoload/insert_suspend_hlsearch.vim | 23 +++++++++++++++++++++++ plugin/insert_suspend_hlsearch.vim | 27 ++------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 autoload/insert_suspend_hlsearch.vim diff --git a/autoload/insert_suspend_hlsearch.vim b/autoload/insert_suspend_hlsearch.vim new file mode 100644 index 0000000..3000ac1 --- /dev/null +++ b/autoload/insert_suspend_hlsearch.vim @@ -0,0 +1,23 @@ +" Initialise option saving variable +if !exists('g:insert_suspend_hlsearch#save') + let g:insert_suspend_hlsearch#save = 0 +endif + +" 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! insert_suspend_hlsearch#Suspend() abort + let g:insert_suspend_hlsearch#save = &hlsearch + if g:insert_suspend_hlsearch#save + set nohlsearch + endif +endfunction + +" Restore the value of 'hlsearch' from the last time s:HlsearchSuspend was +" called. +function! insert_suspend_hlsearch#Restore() abort + if g:insert_suspend_hlsearch#save + set hlsearch + unlet g:insert_suspend_hlsearch#save + endif +endfunction diff --git a/plugin/insert_suspend_hlsearch.vim b/plugin/insert_suspend_hlsearch.vim index afd8800..5dd1e74 100644 --- a/plugin/insert_suspend_hlsearch.vim +++ b/plugin/insert_suspend_hlsearch.vim @@ -14,33 +14,10 @@ if !has('autocmd') || !has('extra_search') || v:version < 700 endif let g:loaded_insert_suspend_hlsearch = 1 -" 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:HlsearchSuspend() - let s:hlsearch_save = &hlsearch - if s:hlsearch_save - set nohlsearch - endif -endfunction - -" Restore the value of 'hlsearch' from the last time s:HlsearchSuspend was -" called. -function! s:HlsearchRestore() - if s:hlsearch_save - set hlsearch - endif - unlet s:hlsearch_save -endfunction - " Clear search highlighting as soon as I enter insert mode, and restore it " once left augroup insert_suspend_hlsearch autocmd! - autocmd InsertEnter - \ * - \ call HlsearchSuspend() - autocmd InsertLeave - \ * - \ call HlsearchRestore() + autocmd InsertEnter * call insert_suspend_hlsearch#Suspend() + autocmd InsertLeave * call insert_suspend_hlsearch#Restore() augroup END -- cgit v1.2.3