From 6d86b086fd480c2403eb93775f72ac67aea41ca1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 14 Dec 2019 17:32:10 +0100 Subject: Move functions to autoload/ --- autoload/nohai.vim | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 autoload/nohai.vim (limited to 'autoload') diff --git a/autoload/nohai.vim b/autoload/nohai.vim new file mode 100644 index 0000000..726d4c8 --- /dev/null +++ b/autoload/nohai.vim @@ -0,0 +1,43 @@ +" Remaps in command mode to run `nohlsearch` after accepting the command. +function! s:AddMapping() + silent! cnoremap CRAndNohlsearch() +endfunction + +" Removes the Nohai cmap. +function! s:RemoveMapping() + silent! cunmap +endfunction + +" Deactivates the Nohai cmap and turns off the augroup. +function! s:Deactivate() + call s:RemoveMapping() + call s:AutocmdOff() +endfunction + +" Expr mapping function that runs the `nohlsearch` command after pressing . +function! s:CRAndNohlsearch() + return "\:nohlsearch\" +endfunction + +" Turn on Nohai autocmds. +function! s:AutocmdOn() + augroup nohai + autocmd! + + autocmd CmdlineEnter [/\?] call s:AddMapping() + autocmd CmdlineLeave [/\?] call s:Deactivate() + augroup END +endfunction + +" Removes the Nohai augroup. +function! s:AutocmdOff() + autocmd! nohai +endfunction + +" Expr mapping function that turns on Nohai and starts the search command +" specified by `command`, either '/' or '?'. +function! nohai#Search(command) + call s:AutocmdOn() + + return a:command +endfunction -- cgit v1.2.3