aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/nohai.vim
diff options
context:
space:
mode:
authorTeddy Wing2019-12-18 01:31:09 +0100
committerTeddy Wing2019-12-19 07:48:11 +0100
commit9eef44718da202b17d360e5189a8d3b79cf6c74a (patch)
treee02ed879351b3baad1a216a225df6c1be013df5a /autoload/nohai.vim
parentabd703bb85df9df6ee532c0f3b051d77deb76f2f (diff)
downloadvim-nohai-extra-mode-maps.tar.bz2
Make visual and operator-pending mode mappings workextra-mode-maps
The existing `s:CRAndNohlsearch()` function doesn't work as-is in visual or operator-pending modes. Add special handling for these modes that results in the <CR> command mode mapping behaving differently in order to support a selection. TODO: Need to handle `cg/` `cg?`. Currently this inserts `hlsearch<CR>gv`.
Diffstat (limited to 'autoload/nohai.vim')
-rw-r--r--autoload/nohai.vim24
1 files changed, 18 insertions, 6 deletions
diff --git a/autoload/nohai.vim b/autoload/nohai.vim
index 71f7f3a..2d9592e 100644
--- a/autoload/nohai.vim
+++ b/autoload/nohai.vim
@@ -14,8 +14,12 @@
" along with Nohai. If not, see <https://www.gnu.org/licenses/>.
" Remaps <CR> in command mode to run `nohlsearch` after accepting the command.
-function! s:AddMapping()
- cnoremap <expr> <silent> <CR> <SID>CRAndNohlsearch()
+function! s:AddMapping(mode)
+ if a:mode ==# 'n'
+ cnoremap <expr> <silent> <CR> <SID>CRAndNohlsearch()
+ elseif a:mode ==# 'v' || a:mode ==# 'o'
+ cnoremap <expr> <silent> <CR> <SID>CRAndNohlsearchV()
+ endif
endfunction
" Removes the Nohai <CR> cmap.
@@ -34,12 +38,20 @@ function! s:CRAndNohlsearch()
return "\<CR>:nohlsearch\<CR>"
endfunction
+function! s:CRAndNohlsearchV()
+ let expr = "\<CR>"
+ let expr .= ":\<C-u>nohlsearch\<CR>"
+ let expr .= 'gv'
+
+ return expr
+endfunction
+
" Turn on Nohai autocmds.
-function! s:AutocmdOn()
+function! s:AutocmdOn(mode)
augroup nohai
autocmd!
- autocmd CmdlineEnter [/\?] call s:AddMapping()
+ execute 'autocmd CmdlineEnter [/\?] call s:AddMapping("' . a:mode . '")'
autocmd CmdlineLeave [/\?] call s:Deactivate()
augroup END
endfunction
@@ -51,8 +63,8 @@ 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()
+function! nohai#Search(command, mode)
+ call s:AutocmdOn(a:mode)
return a:command
endfunction