aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/nohai.vim
blob: 726d4c835b15671379cd5fec4881d1ff31de4a9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
" Remaps <CR> in command mode to run `nohlsearch` after accepting the command.
function! s:AddMapping()
	silent! cnoremap <expr> <CR> <SID>CRAndNohlsearch()
endfunction

" Removes the Nohai <CR> cmap.
function! s:RemoveMapping()
	silent! cunmap <CR>
endfunction

" Deactivates the Nohai <CR> 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 <CR>.
function! s:CRAndNohlsearch()
	return "\<CR>:nohlsearch\<CR>"
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