Created
July 1, 2020 05:24
-
-
Save eikenb/a5f5043a78be1914e86287e849572b41 to your computer and use it in GitHub Desktop.
Simple auto-pair vim config.
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
if exists("did_pairs") | finish | endif | |
let did_pairs = 1 | |
" wiki page: http://vim.wikia.com/wiki/Automatically_append_closing_characters | |
" let me turn it off when I want | |
let b:PairOn=1 | |
function PairsToggle() | |
if exists("b:PairOn") && b:PairOn | |
let b:PairOn = 0 | |
else | |
let b:PairOn = 1 | |
endif | |
endfunction | |
" <C-G>U is a new binding in patch 7.4.849 | |
" Allows for moving of cursor w/o starting new undo sequence | |
function! s:maybematch(match) | |
if ! exists("b:PairOn") || b:PairOn | |
" only insert if end of line and not start of line | |
if col('$') == col('.') && col('.') > 2 | |
return a:match . repeat("\<C-G>U\<Left>", len(a:match)) | |
endif | |
endif | |
return '' | |
endfunction | |
inoremap ( (<C-R>=<SID>maybematch(')')<CR> | |
inoremap [ [<C-R>=<SID>maybematch(']')<CR> | |
inoremap { {<C-R>=<SID>maybematch('}')<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment