From d0e9a9d46875a97ad1b95da1c7716ce48a762f75 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 28 Oct 2017 14:20:10 -0400 Subject: remove quotes in pairs if they are empty --- vimrc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'vimrc') diff --git a/vimrc b/vimrc index 3f1f785..ab72017 100644 --- a/vimrc +++ b/vimrc @@ -480,6 +480,25 @@ function s:move_cursor_right() \] call setpos('.', l:newpos) endfunction +let s:pair_bs_maps = { +\ '"': "maybe_remove_adjacent_char('\"')", +\ "'": "maybe_remove_adjacent_char(\"'\")", +\} +function s:maybe_remove_matching_pair() + let l:prevchar = strpart(getline('.'), col('.')-2, 1) + if has_key(s:pair_bs_maps, l:prevchar) + return eval(s:pair_bs_maps[l:prevchar]) + endif + return "\" +endfunction +function s:maybe_remove_adjacent_char(char) + if strpart(getline('.'), col('.')-1, 1) == a:char + call s:move_cursor_right() + return "\\" + else + return "\" + endif +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" @@ -487,6 +506,7 @@ for s:pair in [['(', ')'], ['{', '}'], ['[', ']']] 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() " }}} " Prompt to create directories if they don't exist {{{ autocmd vimrc BufNewFile * :call ensure_dir_exists() -- cgit v1.2.3-54-g00ecf