mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 21:24:51 +08:00
Don't break undo sequence when moving in insert mode
Since Vim version 7.4.849 [1] we can move in insert mode without breaking the undo sequence by inserting <C-G>U before the movement key. Add s:joinUndo which returns "\<C-G>U" if available. Use s:joinUndo before doing any <Left> or <Right> movements in insert mode to keep a single undo point which can be repeated and undone with a single command. [1] https://github.com/vim/vim/releases/tag/v7.4.849
This commit is contained in:
@@ -329,7 +329,7 @@ function! delimitMate#SkipDelim(char) "{{{
|
|||||||
return a:char . "\<Del>"
|
return a:char . "\<Del>"
|
||||||
elseif delimitMate#IsEmptyPair( pre . a:char )
|
elseif delimitMate#IsEmptyPair( pre . a:char )
|
||||||
" Add closing delimiter and jump back to the middle.
|
" Add closing delimiter and jump back to the middle.
|
||||||
return a:char . "\<Left>"
|
return a:char . s:joinUndo() . "\<Left>"
|
||||||
else
|
else
|
||||||
" Nothing special here, return the same character.
|
" Nothing special here, return the same character.
|
||||||
return a:char
|
return a:char
|
||||||
@@ -360,7 +360,7 @@ function! delimitMate#ParenDelim(right) " {{{
|
|||||||
else
|
else
|
||||||
let tail = ''
|
let tail = ''
|
||||||
endif
|
endif
|
||||||
return left . a:right . tail . repeat("\<Left>", len(split(tail, '\zs')) + 1)
|
return left . a:right . tail . repeat(s:joinUndo() . "\<Left>", len(split(tail, '\zs')) + 1)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! delimitMate#QuoteDelim(char) "{{{
|
function! delimitMate#QuoteDelim(char) "{{{
|
||||||
@@ -376,7 +376,7 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
let right_q = s:rquote(a:char)
|
let right_q = s:rquote(a:char)
|
||||||
let quotes = right_q > left_q + 1 ? 0 : left_q - right_q + 2
|
let quotes = right_q > left_q + 1 ? 0 : left_q - right_q + 2
|
||||||
let lefts = quotes - 1
|
let lefts = quotes - 1
|
||||||
return repeat(a:char, quotes) . repeat("\<Left>", lefts)
|
return repeat(a:char, quotes) . repeat(s:joinUndo() . "\<Left>", lefts)
|
||||||
elseif char_at == a:char
|
elseif char_at == a:char
|
||||||
" Inside an empty pair, jump out
|
" Inside an empty pair, jump out
|
||||||
return a:char . "\<Del>"
|
return a:char . "\<Del>"
|
||||||
@@ -391,7 +391,7 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
\ && !empty(s:get('smart_quotes'))
|
\ && !empty(s:get('smart_quotes'))
|
||||||
" Seems like we have an unbalanced quote, insert one quotation
|
" Seems like we have an unbalanced quote, insert one quotation
|
||||||
" mark and jump to the middle.
|
" mark and jump to the middle.
|
||||||
return a:char . "\<Left>"
|
return a:char . s:joinUndo() . "\<Left>"
|
||||||
else
|
else
|
||||||
" Insert a pair and jump to the middle.
|
" Insert a pair and jump to the middle.
|
||||||
let sufix = ''
|
let sufix = ''
|
||||||
@@ -401,7 +401,7 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
let has_marker = marker == s:get('eol_marker')
|
let has_marker = marker == s:get('eol_marker')
|
||||||
let sufix = !has_marker ? s:get('eol_marker') : ''
|
let sufix = !has_marker ? s:get('eol_marker') : ''
|
||||||
endif
|
endif
|
||||||
return a:char . a:char . "\<Left>"
|
return a:char . a:char . s:joinUndo() . "\<Left>"
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
@@ -416,9 +416,9 @@ function! delimitMate#JumpOut(char) "{{{
|
|||||||
" Ref: https://github.com/Raimondi/delimitMate/issues/168
|
" Ref: https://github.com/Raimondi/delimitMate/issues/168
|
||||||
return "\<Del>".a:char
|
return "\<Del>".a:char
|
||||||
elseif jump == 3
|
elseif jump == 3
|
||||||
return "\<Right>\<Right>"
|
return s:joinUndo() . "\<Right>" . s:joinUndo() . "\<Right>"
|
||||||
elseif jump == 5
|
elseif jump == 5
|
||||||
return "\<Down>\<C-O>I\<Right>"
|
return "\<Down>\<C-O>I" . s:joinUndo() . "\<Right>"
|
||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
@@ -435,12 +435,12 @@ function! delimitMate#JumpAny(...) " {{{
|
|||||||
let char = s:get_char(0)
|
let char = s:get_char(0)
|
||||||
if char == " "
|
if char == " "
|
||||||
" Space expansion.
|
" Space expansion.
|
||||||
return "\<Right>\<Right>"
|
return s:joinUndo() . "\<Right>" . s:joinUndo() . "\<Right>"
|
||||||
elseif char == ""
|
elseif char == ""
|
||||||
" CR expansion.
|
" CR expansion.
|
||||||
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>\<Del>"
|
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>\<Del>"
|
||||||
else
|
else
|
||||||
return "\<Right>"
|
return s:joinUndo() . "\<Right>"
|
||||||
endif
|
endif
|
||||||
endfunction " delimitMate#JumpAny() }}}
|
endfunction " delimitMate#JumpAny() }}}
|
||||||
|
|
||||||
@@ -451,10 +451,10 @@ function! delimitMate#JumpMany() " {{{
|
|||||||
for char in line
|
for char in line
|
||||||
if index(s:get('quotes_list'), char) >= 0 ||
|
if index(s:get('quotes_list'), char) >= 0 ||
|
||||||
\ index(s:get('right_delims'), char) >= 0
|
\ index(s:get('right_delims'), char) >= 0
|
||||||
let rights .= "\<Right>"
|
let rights .= s:joinUndo() . "\<Right>"
|
||||||
let found = 1
|
let found = 1
|
||||||
elseif found == 0
|
elseif found == 0
|
||||||
let rights .= "\<Right>"
|
let rights .= s:joinUndo() . "\<Right>"
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
@@ -487,7 +487,7 @@ function! delimitMate#ExpandReturn() "{{{
|
|||||||
\ && !search(escape(s:get('eol_marker'), '[]\.*^$').'$', 'cnW', '.')
|
\ && !search(escape(s:get('eol_marker'), '[]\.*^$').'$', 'cnW', '.')
|
||||||
let tail = getline('.')[col('.') - 1 : ]
|
let tail = getline('.')[col('.') - 1 : ]
|
||||||
let times = len(split(tail, '\zs'))
|
let times = len(split(tail, '\zs'))
|
||||||
let val .= repeat("\<Right>", times) . s:get('eol_marker') . repeat("\<Left>", times + 1)
|
let val .= repeat(s:joinUndo() . "\<Right>", times) . s:get('eol_marker') . repeat(s:joinUndo() . "\<Left>", times + 1)
|
||||||
endif
|
endif
|
||||||
let val .= "\<CR>"
|
let val .= "\<CR>"
|
||||||
if &smartindent && !&cindent && !&indentexpr
|
if &smartindent && !&cindent && !&indentexpr
|
||||||
@@ -520,7 +520,7 @@ function! delimitMate#ExpandSpace() "{{{
|
|||||||
\ && !escaped
|
\ && !escaped
|
||||||
if s:is_empty_matchpair() || expand_inside_quotes
|
if s:is_empty_matchpair() || expand_inside_quotes
|
||||||
" Expand:
|
" Expand:
|
||||||
return "\<Space>\<Space>\<Left>"
|
return "\<Space>\<Space>" . s:joinUndo() . "\<Left>"
|
||||||
else
|
else
|
||||||
return "\<Space>"
|
return "\<Space>"
|
||||||
endif
|
endif
|
||||||
@@ -656,4 +656,12 @@ function! s:test_mappings(list, is_matchpair) "{{{
|
|||||||
endfor
|
endfor
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:joinUndo() "{{{
|
||||||
|
if v:version < 704
|
||||||
|
\ || ( v:version == 704 && !has('patch849') )
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
return "\<C-G>U"
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2
|
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2
|
||||||
|
|||||||
Reference in New Issue
Block a user