Created
May 28, 2018 18:47
-
-
Save veirus/575b80c5c1728c952e4908f9b0f05c3d to your computer and use it in GitHub Desktop.
Simple function and mappings to close brackets automagically. In practice this shit is more irritating than helpful.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Auto-insert closing parenthesis/brace {{{2 | |
" TODO: make bracket insertion a little smarter | |
" right now it gets in the way more than it helps | |
inoremap ( ()<Left> | |
inoremap { {}<Left> | |
inoremap [ []<Left> | |
" Auto-delete closing parenthesis/brace | |
function! BetterBackSpace() abort | |
let cur_line = getline('.') | |
let before_char = cur_line[col('.')-2] | |
let after_char = cur_line[col('.')-1] | |
if (before_char == '(' && after_char == ')') || (before_char == '{' && after_char == '}') || (before_char == '[' && after_char == ']') | |
return "\<Del>\<BS>" | |
else | |
return "\<BS>" | |
endfunction | |
inoremap <silent> <BS> <C-r>=BetterBackSpace()<CR> | |
" Skip over closing parenthesis/brace | |
inoremap <expr> ) getline('.')[col('.')-1] == ")" ? "\<Right>" : ")" | |
inoremap <expr> } getline('.')[col('.')-1] == "}" ? "\<Right>" : "}" | |
inoremap <expr> ] getline('.')[col('.')-1] == "]" ? "\<Right>" : "]" | |
" }}}2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment