Created
April 26, 2017 03:28
-
-
Save Jeanhwea/dadcc33adebfd8623086fe64ea4fdb9e to your computer and use it in GitHub Desktop.
vim 新行自动添加括号
This file contains hidden or 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
| function! s:OpenSpecial(ochar,cchar) | |
| echo "OpenSpecial" | |
| let line = getline('.') | |
| let col = col('.') - 2 | |
| if(line[col] != a:ochar) | |
| if(col > 0) | |
| return "\<ESC>a\<CR>" | |
| else | |
| return "\<CR>" | |
| endif | |
| endif | |
| if(line[col+1] != a:cchar) | |
| call setline('.',line[:(col)].a:cchar.line[(col+1):]) | |
| else | |
| call setline('.',line[:(col)].line[(col+1):]) | |
| endif | |
| return "\<Esc>a\<CR>;\<CR>".a:cchar."\<Esc>\"_xk$\"_xa" | |
| endfunction | |
| inoremap <silent> <CR> <C-R>=<SID>OpenSpecial('{','}')<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment