diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-30 22:52:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-30 22:52:52 +1200 |
commit | a1f580c76e5af568235cc03582f4310298be7328 (patch) | |
tree | 5c4cd3276bd991fb3a20b3bf8d891725a00a9b9d | |
download | vim-insert-suspend-hlsearch-a1f580c76e5af568235cc03582f4310298be7328.tar.gz vim-insert-suspend-hlsearch-a1f580c76e5af568235cc03582f4310298be7328.zip |
Initial commitv0.1.0
Copied with minimal changes from tejr's dotfiles suite, v0.34.1.
-rw-r--r-- | README.markdown | 14 | ||||
-rw-r--r-- | doc/insert_suspend_hlsearch.txt | 22 | ||||
-rw-r--r-- | plugin/insert_suspend_hlsearch.vim | 47 |
3 files changed, 83 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..2cacbf3 --- /dev/null +++ b/README.markdown @@ -0,0 +1,14 @@ +insert\_suspend\_hlsearch.vim +============================= + +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. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/doc/insert_suspend_hlsearch.txt b/doc/insert_suspend_hlsearch.txt new file mode 100644 index 0000000..3aa7c1f --- /dev/null +++ b/doc/insert_suspend_hlsearch.txt @@ -0,0 +1,22 @@ +*insert_suspend_hlsearch.txt* For Vim version 7.0 Last change: 2018 May 30 + +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. + +REQUIREMENTS *insert_suspend_hlsearch-requirements* + +This plugin is only available if 'compatible' is not set. It also requires the +|+autocmd| and |+extra_search| features. + +AUTHOR *insert_suspend_hlsearch-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *insert_suspend_hlsearch-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/insert_suspend_hlsearch.vim b/plugin/insert_suspend_hlsearch.vim new file mode 100644 index 0000000..b916ac4 --- /dev/null +++ b/plugin/insert_suspend_hlsearch.vim @@ -0,0 +1,47 @@ +" +" 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 <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('g:loaded_insert_suspend_hlsearch') || &compatible + finish +endif +if !has('autocmd') || !has('extra_search') || v:version < 700 + finish +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 = &hlsearch + if s:hlsearch + set nohlsearch + endif + return +endfunction + +" Restore the value of 'hlsearch' from the last time s:HlsearchSuspend was +" called. +function s:HlsearchRestore() + if s:hlsearch + set hlsearch + endif + return +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() +augroup END |