From 46ae99cc9ebc11d188bbd3ae774ca2716863399f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 28 Oct 2017 17:39:18 -0400 Subject: make enter work more cleanly having a separate map for ( can time out, and delays screen updating --- vimrc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'vimrc') diff --git a/vimrc b/vimrc index 96bb14b..84ded14 100644 --- a/vimrc +++ b/vimrc @@ -470,6 +470,21 @@ 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]) endfunction +let s:pair_cr_maps = { +\ '(': "go_up()", +\ '[': "go_up()", +\ '{': "go_up()", +\} +function s:maybe_reposition_cursor() + let l:prevchar = strpart(getline('.'), col('.')-2, 1) + if has_key(s:pair_cr_maps, l:prevchar) + return eval(s:pair_cr_maps[l:prevchar]) + endif + return "\" +endfunction +function s:go_up() + return "\\O" +endfunction let s:pair_bs_maps = { \ '"': "maybe_remove_adjacent_char('\"')", \ "'": "maybe_remove_adjacent_char(\"'\")", @@ -527,12 +542,12 @@ function s:chars_between(start, end) 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()?'':''\" inoremap =maybe_remove_matching_pair() +inoremap =maybe_reposition_cursor() " }}} " Prompt to create directories if they don't exist {{{ autocmd vimrc BufNewFile * :call ensure_dir_exists() -- cgit v1.2.3-54-g00ecf