aboutsummaryrefslogtreecommitdiff
path: root/autoload/insert_suspend_hlsearch.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:52:10 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:52:10 +1200
commitcbdb61b624caa1670e091f901c2bdd7e76e05414 (patch)
treec4eb163b3ce0cfa5963cba0d7b4031249e9fc02f /autoload/insert_suspend_hlsearch.vim
parent8679b3bb7124d3fe44d260ebec202c92d6695bcc (diff)
parent269c464e1246622ae7eeae6ade44182edf816995 (diff)
downloadvim-insert-suspend-hlsearch-cbdb61b624caa1670e091f901c2bdd7e76e05414.tar.gz
vim-insert-suspend-hlsearch-cbdb61b624caa1670e091f901c2bdd7e76e05414.zip
Merge branch 'release/v2.1.0'HEADv2.1.0master
* release/v2.1.0: Further refactor/simplify
Diffstat (limited to 'autoload/insert_suspend_hlsearch.vim')
-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