From e1480ad9ff8ecb6318110f940b7d4fc79ae8918e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 28 Oct 2017 19:44:11 -0400 Subject: stop manually moving the cursor around it looks like vim is super buggy with how this interacts with undo (it seems to just corrupt even previous entries in the undo tree, somehow?). this makes undo work again, but doesn't fix `.`, because all of these commands start new actions (it's odd that actions and undo blocks aren't the same here, honestly), but i think i might be able to work around that in a similar way to repeat.vim. --- vimrc | 49 +++++++++++++------------------------------------ 1 file changed, 13 insertions(+), 36 deletions(-) (limited to 'vimrc') diff --git a/vimrc b/vimrc index 3abdffd..79072f5 100644 --- a/vimrc +++ b/vimrc @@ -459,16 +459,7 @@ xnoremap K :call Help(1, [], 'man') " }}} " auto-append closing characters {{{ function s:move_cursor_left() - let [l:bufnr, l:lnum, l:col, l:off, l:curswant] = getcurpos() - call setpos('.', [l:bufnr, l:lnum, l:col - 1, 0, l:col - 1]) -endfunction -function s:move_cursor_right() - let [l:bufnr, l:lnum, l:col, l:off, l:curswant] = getcurpos() - call setpos('.', [l:bufnr, l:lnum, l:col + 1, 0, l:col + 1]) -endfunction -function s:move_cursor_to_pos(lnum, col) - let [l:bufnr, l:lnum, l:col, l:off, l:curswant] = getcurpos() - call setpos('.', [l:bufnr, a:lnum, a:col, 0, a:col]) + return "\i" endfunction function s:prevchar() return getline('.')[col('.') - 2] @@ -489,7 +480,7 @@ function s:maybe_reposition_cursor() return "\" endfunction function s:go_up() - return "\\O" + return "\\O" endfunction let s:pair_bs_maps = { \ '"': "maybe_remove_adjacent_char('\"')", @@ -507,8 +498,7 @@ function s:maybe_remove_matching_pair() endfunction function s:maybe_remove_adjacent_char(char) if s:nextchar() == a:char - call s:move_cursor_right() - return "\\" + return "\\" else return "\" endif @@ -525,41 +515,28 @@ function s:maybe_remove_empty_pair(char) return "\" endif - call s:move_cursor_to_pos(l:end[0], l:end[1] + 1) - return repeat("\", 2 + s:chars_between(l:start, l:end)) -endfunction -function s:chars_between(start, end) - if a:start[0] == a:end[0] - return a:end[1] - a:start[1] + let l:diff = [l:end[0] - l:start[0], l:end[1] - l:start[1]] + if l:diff[0] == 0 + return "\" . repeat("\", l:diff[1] + 1) + elseif l:diff[0] == 1 + return "\" . (l:diff[0] + 1) . "Ji" . "\\\" else - let l:line = getline(a:start[0]) - let l:after_first = strpart(l:line, a:start[1] - 1) - - let l:line = getline(a:end[0]) - let l:before_last = strpart(l:line, 0, a:end[1] - 1) - - let l:nchars = len(l:after_first) + len(l:before_last) + 1 - for l:idx in range(a:start[0] + 1, a:end[0] - 1) - let l:nchars = l:nchars + len(getline(l:idx)) + 1 - endfor - - return l:nchars + return "\" . (l:diff[0] + 1) . "Ji" . "\\\" endif endfunction function s:skip_closing_char(char) if s:nextchar() == a:char - call s:move_cursor_right() - return '' + return "\la" else return a:char endif endfunction for [s:start, s:end] in [['(', ')'], ['{', '}'], ['[', ']']] - exe "inoremap ".s:start." ".s:start.s:end."=move_cursor_left()?'':''" + exe "inoremap ".s:start." ".s:start.s:end."=move_cursor_left()" exe "inoremap ".s:end." =skip_closing_char('".s:end."')" endfor -inoremap ' nextchar() == "'" ? "\=\skip_closing_char(\"'\")\" : col('.') == 1 \|\| match(prevchar(), '\W') != -1 ? "''\=\move_cursor_left()?'':''\" : "'" -inoremap " nextchar() == '"' ? "\=\skip_closing_char('\"')\" : "\"\"\=\move_cursor_left()?'':''\" +inoremap ' nextchar() == "'" ? "\=\skip_closing_char(\"'\")\" : col('.') == 1 \|\| match(prevchar(), '\W') != -1 ? "''\=\move_cursor_left()\" : "'" +inoremap " nextchar() == '"' ? "\=\skip_closing_char('\"')\" : "\"\"\=\move_cursor_left()\" inoremap =maybe_remove_matching_pair() inoremap =maybe_reposition_cursor() " }}} -- cgit v1.2.3-54-g00ecf