aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:51:16 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:51:16 +1200
commit612260817d2bf7d88ee6e7b4e8f69d7de2deee5b (patch)
treea68f57250bb28e19f7825e5a06e98256c061b5a4 /autoload
parentMerge branch 'release/v2.0.0' into develop (diff)
downloadvim-insert-suspend-hlsearch-612260817d2bf7d88ee6e7b4e8f69d7de2deee5b.tar.gz
vim-insert-suspend-hlsearch-612260817d2bf7d88ee6e7b4e8f69d7de2deee5b.zip
Further refactor/simplify
Diffstat (limited to 'autoload')
-rw-r--r--autoload/insert_suspend_hlsearch.vim13
1 files changed, 10 insertions, 3 deletions
diff --git a/autoload/insert_suspend_hlsearch.vim b/autoload/insert_suspend_hlsearch.vim
index de43d10..4408d52 100644
--- a/autoload/insert_suspend_hlsearch.vim
+++ b/autoload/insert_suspend_hlsearch.vim
@@ -1,8 +1,15 @@
-" Save value of 'hlsearch' into a variable, and disable it
+" Suspend 'hlsearch' if set, add hook to restore on insert completion
function! insert_suspend_hlsearch#() abort
- let s:hlsearch = &hlsearch
+
+ " Nothing to do if 'hlsearch' isn't set
+ if !&hlsearch
+ return
+ endif
+
+ " Turn off 'hlsearch' and set a hook to re-enable it when insert mode ends
set nohlsearch
autocmd insert_suspend_hlsearch InsertLeave *
- \ let &hlsearch = s:hlsearch
+ \ set hlsearch
\|autocmd! insert_suspend_hlsearch InsertLeave
+
endfunction