From 4ebbac1a1686b06cd30907312fa7646c8ede7f71 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 27 Oct 2017 20:33:57 -0400 Subject: better auto-appending of closing characters make undo actually work properly again --- vimrc | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'vimrc') diff --git a/vimrc b/vimrc index 5bb491f..d49f108 100644 --- a/vimrc +++ b/vimrc @@ -147,15 +147,6 @@ inoremap gj nnoremap :%!xxd nnoremap :%!xxd -r " }}} -" auto-append closing characters {{{ -for s:pair in [['(', ')'], ['{', '}'], ['[', ']']] - exe "inoremap " . s:pair[0] . " " . s:pair[0] . s:pair[1] . "" - exe "inoremap " . s:pair[0] . " " . s:pair[0] . "" . s:pair[1] . "O" - exe "inoremap " . s:pair[1] . " strpart(getline('.'), col('.')-1, 1) == '" . s:pair[1] . "' ? '' : '" . s:pair[1] . "'" -endfor -inoremap ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\" : "\'" -inoremap " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\" : "\"\"\" -" }}} " tab for completion {{{ inoremap strpart(getline('.'), 0, col('.')-1) =~ '^\s*$' ? "\" : "\" inoremap @@ -496,5 +487,36 @@ endfunction nnoremap K :call Help(0, [], 'man') xnoremap K :call Help(1, [], 'man') " }}} +" auto-append closing characters {{{ +function s:move_cursor_left() + let l:pos = getcurpos() + let l:newpos = [ + \ l:pos[0], + \ l:pos[1], + \ l:pos[2] - 1, + \ l:pos[3], + \ l:pos[2] - 1, + \] + call setpos('.', l:newpos) +endfunction +function s:move_cursor_right() + let l:pos = getcurpos() + let l:newpos = [ + \ l:pos[0], + \ l:pos[1], + \ l:pos[2] + 1, + \ l:pos[3], + \ l:pos[2] + 1, + \] + call setpos('.', l:newpos) +endfunction +for s:pair in [['(', ')'], ['{', '}'], ['[', ']']] + exe "inoremap " . s:pair[0] . " " . s:pair[0] . s:pair[1] . "=move_cursor_left()?\"\":\"\"" + exe "inoremap " . s:pair[0] . " " . s:pair[0] . "" . s:pair[1] . "O" + exe "inoremap " . s:pair[1] . " strpart(getline('.'), col('.')-1, 1) == '" . s:pair[1] . "' ? '=move_cursor_right()?\"\":\"\"' : '" . s:pair[1] . "'" +endfor +inoremap ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\=\move_cursor_right()?'':''\" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\=\move_cursor_left()?'':''\" : "\'" +inoremap " strpart(getline('.'), col('.')-1, 1) == '"' ? "\=\move_cursor_right()?'':''\" : "\"\"\=\move_cursor_left()?'':''\" +" }}} " }}} " vim: fdm=marker -- cgit v1.2.3-54-g00ecf