0%

vim按下回车后大括号自动换行缩进

问题描述: 在一对大括号之间回车,自动分为3行并调整缩进

代码:

1
2
3
4
5
6
7
8
9
10
11
" 大括号自动分行, C/C++下的自动命令
autocmd BufWritePre,BufRead *.c :inoremap <Enter> <c-r>=BracketsEnter('}')<CR>
autocmd BufWritePre,BufRead *.cpp :inoremap <Enter> <c-r>=BracketsEnter('}')<CR>

function BracketsEnter(char)
if getline('.')[col('.')-1] == a:char
return "\<Enter>\<Tab>\<Esc>mpa\<Enter>\<Esc>`pa"
else
return "\<Enter>"
endif
endf
Thank you for your reward !