aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-17 15:47:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-17 15:47:58 +1200
commit6e626e4f4b969480495a72ce94599be8c85351f6 (patch)
treee5d066fce1e599c56651e4c10db1098eb4999a98
parentAdd VERSION (diff)
downloadvim-insert-suspend-hlsearch-6e626e4f4b969480495a72ce94599be8c85351f6.tar.gz
vim-insert-suspend-hlsearch-6e626e4f4b969480495a72ce94599be8c85351f6.zip
Use autoload since we have Vim >= 7.0
-rw-r--r--autoload/insert_suspend_hlsearch.vim23
-rw-r--r--plugin/insert_suspend_hlsearch.vim27
2 files changed, 25 insertions, 25 deletions
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 <SID>HlsearchSuspend()
- autocmd InsertLeave
- \ *
- \ call <SID>HlsearchRestore()
+ autocmd InsertEnter * call insert_suspend_hlsearch#Suspend()
+ autocmd InsertLeave * call insert_suspend_hlsearch#Restore()
augroup END