diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-25 22:48:27 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-25 22:48:27 +1200 |
commit | 2d5dd9304a2c372e5519c67d2d600e874fceee1e (patch) | |
tree | d29a1ecda3d665fce94d6cebd959e11106d9a62d | |
parent | Merge branch 'release/v0.7.0' into develop (diff) | |
download | vim-insert-suspend-hlsearch-2d5dd9304a2c372e5519c67d2d600e874fceee1e.tar.gz vim-insert-suspend-hlsearch-2d5dd9304a2c372e5519c67d2d600e874fceee1e.zip |
Overhaul with autoloading for new version
-rw-r--r-- | autoload/insert_suspend_hlsearch.vim | 14 | ||||
-rw-r--r-- | doc/insert_suspend_hlsearch.txt | 13 | ||||
-rw-r--r-- | plugin/insert_suspend_hlsearch.vim | 32 |
3 files changed, 26 insertions, 33 deletions
diff --git a/autoload/insert_suspend_hlsearch.vim b/autoload/insert_suspend_hlsearch.vim new file mode 100644 index 0000000..4961ed9 --- /dev/null +++ b/autoload/insert_suspend_hlsearch.vim @@ -0,0 +1,14 @@ +" Save value of 'hlsearch' into a variable, and disable it +function! insert_suspend_hlsearch#Suspend() abort + let s:hlsearch = &hlsearch + let &hlsearch = 0 +endfunction + +" Restore the value of 'hlsearch' if suspended +function! insert_suspend_hlsearch#Restore() abort + if !exists('s:hlsearch') + return + endif + let &hlsearch = s:hlsearch + unlet s:hlsearch +endfunction diff --git a/doc/insert_suspend_hlsearch.txt b/doc/insert_suspend_hlsearch.txt index 56bee0e..304e8e2 100644 --- a/doc/insert_suspend_hlsearch.txt +++ b/doc/insert_suspend_hlsearch.txt @@ -1,15 +1,16 @@ -*insert_suspend_hlsearch.txt* For Vim version 7.0 Last change: 2018 June 17 +*insert_suspend_hlsearch.txt* For Vim version 7.0 Last change: 2019 May 25 DESCRIPTION *insert_suspend_hlsearch* -This plugin quietly disables 'hlsearch' search highlighting if enabled when an -insert operation is started, and puts it back once done, to avoid the -distracting effect the highlighting can cause while writing. +This plugin disables 'hlsearch' search highlighting if enabled when an insert +operation is started, and puts it back once done, to avoid the distracting +effect the highlighting can cause while writing. Its implementation is a +crude workaround for the |:nohlsearch| limitations described in +|autocmd-searchpat|. REQUIREMENTS *insert_suspend_hlsearch-requirements* -This plugin is only available if 'compatible' is not set. It also requires -the |+autocmd| and |+extra_search| features. +This plugin is only available if 'compatible' is not set. AUTHOR *insert_suspend_hlsearch-author* diff --git a/plugin/insert_suspend_hlsearch.vim b/plugin/insert_suspend_hlsearch.vim index 635ed8e..2a88e8a 100644 --- a/plugin/insert_suspend_hlsearch.vim +++ b/plugin/insert_suspend_hlsearch.vim @@ -6,39 +6,17 @@ " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if exists('loaded_insert_suspend_hlsearch') || &compatible - finish -endif -if !has('autocmd') || !has('extra_search') || v:version < 700 +if exists('loaded_insert_suspend_hlsearch') || &compatible && v:version < 700 finish endif let loaded_insert_suspend_hlsearch = 1 -" Initialise option saving variable -let s:hlsearch_save = &hlsearch - -" 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:Suspend() abort - let s:hlsearch_save = &hlsearch - if &hlsearch - set nohlsearch - endif -endfunction - -" Restore the value of 'hlsearch' from the last time s:HlsearchSuspend was -" called. -function! s:Restore() abort - if !&hlsearch && s:hlsearch_save - set hlsearch - endif -endfunction - " Clear search highlighting as soon as I enter insert mode, and restore it " once left augroup insert_suspend_hlsearch autocmd! - autocmd InsertEnter * call s:Suspend() - autocmd InsertLeave * call s:Restore() + autocmd InsertEnter * + \ call insert_suspend_hlsearch#Suspend() + autocmd InsertLeave * + \ call insert_suspend_hlsearch#Restore() augroup END |