vim
if ( 1 ) { printf( "%d\n", (int) sage ); hoge(); }
のように自動的にカッコを入れるスクリプト。
function! ShouldPad() let c = getline(line("."))[col(".") - 1] normal! mzh let word = expand("<cword>") if c =~ "[A-Za-z_]" || word == "if" || word == "for" || word == "while" || word == "switch" return 1 else return 0 endif endfunction function! AutoPadding() if ShouldPad() normal! `z exe "normal! a(\<Space>" else normal! `z exe "normal! a(" endif endfunction function! AutoPaddingAfter( ) let c = getline(line("."))[col(".") - 1] if c == " " normal! xa) return endif normal! my normal! a) normal! %h if ShouldPad() exe "normal! `ylxa\<Space>\)" else exe "normal! `ylxa)" endif endfunction inoremap ( <Esc>:call AutoPadding()<CR>a inoremap ) <Esc>:call AutoPaddingAfter()<CR>a