Add insert mode map <c-g>% to jump between matches

This commit is contained in:
Andy K. Massimino
2018-06-05 22:06:29 -04:00
parent a8844c53e0
commit 8c323afe3c
2 changed files with 24 additions and 0 deletions

View File

@@ -126,6 +126,8 @@ function! s:init_default_mappings()
call s:map('o', l:opforce.'z%',
\ '<plug>(matchup-o_'.l:opforce.')<plug>(matchup-z%)')
endfor
call s:map('i', '<c-g>%', '<plug>(matchup-c_g%)')
endif
if get(g:, 'matchup_text_obj_enabled', 0)
@@ -201,6 +203,9 @@ function! s:motion_init_module() " {{{1
onoremap <silent> <plug>(matchup-z%)
\ :<c-u>call matchup#motion#op('z%')<cr>
inoremap <silent> <plug>(matchup-c_g%)
\ <c-\><c-o>:call matchup#motion#insert_mode()<cr>
call matchup#perf#toc('loading_module', 'motion')
endfunction

View File

@@ -256,6 +256,25 @@ function! matchup#motion#jump_inside(visual) " {{{1
call matchup#pos#set_cursor(l:new_pos)
endfunction
" }}}1
function! matchup#motion#insert_mode() " {{{1
call matchup#perf#timeout_start(0) " disable the timeout
let l:delim = matchup#delim#get_current(
\ 'all', 'both_all', {'insertmode': 1})
if empty(l:delim) | return | endif
let l:matches = matchup#delim#get_matching(l:delim, 1)
if len(l:matches) <= (l:delim.side ==# 'mid' ? 2 : 1) | return | endif
if !has_key(l:delim, 'links') | return | endif
let l:delim = get(l:delim.links, 'next', {})
if empty(l:delim) | return | endif
let l:new_pos = [l:delim.lnum, l:delim.cnum]
let l:new_pos[1] += matchup#delim#end_offset(l:delim)
call matchup#pos#set_cursor(matchup#pos#next_eol(l:new_pos))
endfunction
" }}}1
let &cpo = s:save_cpo