diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-10-28 17:39:18 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-10-29 02:01:52 -0400 |
commit | 46ae99cc9ebc11d188bbd3ae774ca2716863399f (patch) | |
tree | 3a25fa58298997683c39cfaa94bbcb7039dc10b8 /vimrc | |
parent | a6d912e02f5c6a8fcd1fb8a52854fcb9782ed07e (diff) | |
download | conf-46ae99cc9ebc11d188bbd3ae774ca2716863399f.tar.gz conf-46ae99cc9ebc11d188bbd3ae774ca2716863399f.zip |
make enter work more cleanly
having a separate map for (<CR> can time out, and delays screen updating
Diffstat (limited to 'vimrc')
-rw-r--r-- | vimrc | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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 = { +\ '(': "<SID>go_up()", +\ '[': "<SID>go_up()", +\ '{': "<SID>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 "\<CR>" +endfunction +function s:go_up() + return "\<CR>\<C-O>O" +endfunction let s:pair_bs_maps = { \ '"': "<SID>maybe_remove_adjacent_char('\"')", \ "'": "<SID>maybe_remove_adjacent_char(\"'\")", @@ -527,12 +542,12 @@ function s:chars_between(start, end) endfunction for s:pair in [['(', ')'], ['{', '}'], ['[', ']']] exe "inoremap <silent> " . s:pair[0] . " " . s:pair[0] . s:pair[1] . "<C-R>=<SID>move_cursor_left()?\"\":\"\"<CR>" - exe "inoremap <silent> " . s:pair[0] . "<CR> " . s:pair[0] . "<CR>" . s:pair[1] . "<Esc>O" exe "inoremap <silent><expr> " . s:pair[1] . " strpart(getline('.'), col('.')-1, 1) == '" . s:pair[1] . "' ? '<C-R>=<SID>move_cursor_right()?\"\":\"\"<CR>' : '" . s:pair[1] . "'" endfor inoremap <silent><expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<C-R>=\<SID>move_cursor_right()?'':''\<CR>" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\<C-R>=\<SID>move_cursor_left()?'':''\<CR>" : "\'" inoremap <silent><expr> " strpart(getline('.'), col('.')-1, 1) == '"' ? "\<C-R>=\<SID>move_cursor_right()?'':''\<CR>" : "\"\"\<C-R>=\<SID>move_cursor_left()?'':''\<CR>" inoremap <silent> <BS> <C-R>=<SID>maybe_remove_matching_pair()<CR> +inoremap <silent> <CR> <C-R>=<SID>maybe_reposition_cursor()<CR> " }}} " Prompt to create directories if they don't exist {{{ autocmd vimrc BufNewFile * :call <SID>ensure_dir_exists() |