summaryrefslogtreecommitdiffstats
path: root/vimrc
diff options
context:
space:
mode:
authorJesse Luehrs <doy@stripe.com>2017-10-26 13:30:31 -0700
committerJesse Luehrs <doy@tozt.net>2017-10-26 13:30:57 -0700
commit21e2d8f8b43302538702fe3ccaed32995c146c96 (patch)
tree546ae2d5b6a49a50c8c68d06b0aca2869a210032 /vimrc
parent91f504a95b6159f1ccaeadf5fefe2dc0e9a3bce7 (diff)
downloadconf-21e2d8f8b43302538702fe3ccaed32995c146c96.tar.gz
conf-21e2d8f8b43302538702fe3ccaed32995c146c96.zip
make auto-appending closing chars more consistent
Diffstat (limited to 'vimrc')
-rw-r--r--vimrc17
1 files changed, 7 insertions, 10 deletions
diff --git a/vimrc b/vimrc
index 34306a0..387e6a2 100644
--- a/vimrc
+++ b/vimrc
@@ -566,16 +566,13 @@ nmap <silent>g) g0
nmap <Bar> \
" }}}
" auto-append closing characters {{{
-inoremap { {}<Left>
-inoremap {<CR> {<CR>}<Esc>O
-inoremap {} {}
-inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
-inoremap ( ()<Left>
-inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
-inoremap [ []<Left>
-inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "]"
-inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<Right>" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\<Left>" : "\'"
-inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
+for pair in [['(', ')'], ['{', '}'], ['[', ']']]
+ exe "inoremap " . pair[0] . " " . pair[0] . pair[1] . "<Left>"
+ exe "inoremap " . pair[0] . "<CR> " . pair[0] . "<CR>" . pair[1] . "<Esc>O"
+ exe "inoremap <expr> " . pair[1] . " strpart(getline('.'), col('.')-1, 1) == '" . pair[1] . "' ? '<Right>' : '" . pair[1] . "'"
+endfor
+inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<Right>" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\<Left>" : "\'"
+inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
" }}}
" tab for completion {{{
inoremap <expr> <Tab> strpart(getline('.'), 0, col('.')-1) =~ '^\s*$' ? "\<Tab>" : "\<C-n>"