Skip to content

Commit

Permalink
Fix undo via <Esc>:undojoin<cr>i (applied via s:get_left_motion)
Browse files Browse the repository at this point in the history
While this fixes the undo chaining in general, `<Left>` is still being
used in block-wise visual mode, where exiting insert mode would also
exit the block-wise mode.

Ref: Raimondi#138
  • Loading branch information
blueyed committed Jun 15, 2014
1 parent 5e96f61 commit 0962a66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 15 additions & 6 deletions autoload/delimitMate.vim
Expand Up @@ -49,6 +49,15 @@ function! s:exists(name, ...) "{{{
return exists(scope . ':' . name)
endfunction "}}}

function! s:get_left_motion()
if get(b:, 'delimitMate_visualmode', '') == ''
" Do not leave insert mode when in block-wise visual mode.
return "\<Left>"
endif
" Move left via "Esc" and "i" to keep the undo chain.
return "\<Esc>:undojoin\<CR>i"
endfunction

function! delimitMate#Set(...) "{{{
return call('s:s', a:000)
endfunction "}}}
Expand Down Expand Up @@ -333,7 +342,7 @@ function! delimitMate#SkipDelim(char) "{{{
return a:char . "\<Del>"
elseif delimitMate#IsEmptyPair( pre . a:char )
" Add closing delimiter and jump back to the middle.
return a:char . "\<Left>"
return a:char . s:get_left_motion()
else
" Nothing special here, return the same character.
return a:char
Expand Down Expand Up @@ -363,7 +372,7 @@ function! delimitMate#ParenDelim(right) " {{{
"if (col) < 0
" call setline('.',a:right.line)
"endif
return left . a:right . tail . repeat("\<Left>", len(split(tail, '\zs')) + 1)
return left . a:right . tail . repeat(s:get_left_motion(), len(split(tail, '\zs')) + 1)
endfunction " }}}

function! delimitMate#QuoteDelim(char) "{{{
Expand All @@ -379,7 +388,7 @@ function! delimitMate#QuoteDelim(char) "{{{
let right_q = delimitMate#RightQ(a:char)
let quotes = right_q > left_q + 1 ? 0 : left_q - right_q + 2
let lefts = quotes - 1
return repeat(a:char, quotes) . repeat("\<Left>", lefts)
return repeat(a:char, quotes) . repeat(s:get_left_motion(), lefts)
elseif char_at == a:char
" Inside an empty pair, jump out
return a:char . "\<Del>"
Expand All @@ -394,7 +403,7 @@ function! delimitMate#QuoteDelim(char) "{{{
\ && s:g('smart_quotes')
" Seems like we have an unbalanced quote, insert one quotation
" mark and jump to the middle.
return a:char . "\<Left>"
return a:char . s:get_left_motion()
else
" Insert a pair and jump to the middle.
let sufix = ''
Expand All @@ -404,7 +413,7 @@ function! delimitMate#QuoteDelim(char) "{{{
let has_marker = marker == s:g('eol_marker')
let sufix = !has_marker ? s:g('eol_marker') : ''
endif
return a:char . a:char . "\<Left>"
return a:char . a:char . s:get_left_motion()
endif
endfunction "}}}

Expand Down Expand Up @@ -515,7 +524,7 @@ function! delimitMate#ExpandSpace() "{{{
\ && !escaped
if delimitMate#WithinEmptyMatchpair() || expand_inside_quotes
" Expand:
return "\<Space>\<Space>\<Left>"
return "\<Space>\<Space>" . s:get_left_motion()
else
return "\<Space>"
endif
Expand Down
5 changes: 5 additions & 0 deletions plugin/delimitMate.vim
Expand Up @@ -368,6 +368,11 @@ augroup delimitMate
\ call <SID>DelimitMateDo() |
\ let b:delimitMate_was_here = 1 |
\ endif

" Keep track of visualmode(), which is used in s:get_left_motion(),
" to skip leaving insert mode in block-wise visual mode.
autocmd InsertEnter * let b:delimitMate_visualmode = visualmode()
autocmd InsertLeave * unlet! b:delimitMate_visualmode
augroup END

"}}}
Expand Down

0 comments on commit 0962a66

Please sign in to comment.