From 54caf02bd794e45ed5b4b181f1e314e924809b1e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 13 Nov 2017 00:02:47 +1300 Subject: Move 'hlsearch' insert-mode suspension into plugin It's easily repackaged and it makes the configuration that much shorter, so I may as well. This version also correctly handles 'hlsearch' not being on in the first place. --- vim/plugin/insert_suspend_hlsearch.vim | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 vim/plugin/insert_suspend_hlsearch.vim (limited to 'vim/plugin') diff --git a/vim/plugin/insert_suspend_hlsearch.vim b/vim/plugin/insert_suspend_hlsearch.vim new file mode 100644 index 00000000..378febc8 --- /dev/null +++ b/vim/plugin/insert_suspend_hlsearch.vim @@ -0,0 +1,48 @@ +" +" insert_suspend_hlsearch.vim: If 'hlsearch' is enabled, switch it off when +" the user starts an insert mode operation, and back on again when they're +" done. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('g:loaded_insert_suspend_hlsearch') || &compatible + finish +endif +" InsertEnter isn't an autocmd event until 7.0 +if !has('autocmd') || v:version < 700 + finish +endif +let g:loaded_insert_suspend_hlsearch = 1 + +" When entering insert mode, copy the current value of the 'hlsearch' option +" into a script variable; if it's enabled, suspend it +function s:InsertEnter() + let s:hlsearch = &hlsearch + echo &hlsearch + if s:hlsearch + set nohlsearch + endif + return +endfunction + +" When leaving insert mode, if 'hlsearch' was enabled when this operation +" started, restore it +function s:InsertLeave() + if s:hlsearch + set hlsearch + endif + return +endfunction + +" Clear search highlighting as soon as I enter insert mode, and restore it +" once I leave it +augroup insert_suspend_hlsearch + autocmd! + autocmd InsertEnter + \ * + \ call InsertEnter() + autocmd InsertLeave + \ * + \ call InsertLeave() +augroup END -- cgit v1.2.3