One of the things that I like most about Xcode is the auto-insertion of a closing curly-brace on the second line below whenever I enter an opening curly-brace, and the insertion of the cursor on the line in-between them. However, at heart I'm still a Vim guy, and tonight I got tired of actually typing that closing curly-brace. So, to make Vim automagically create my curly-brace blocks for me, I did the following.
In my .vimrc, I place the following lines
if has("autocmd")
autocmd FileType c source ~/.vim/brace.vim
autocmd FileType cpp source ~/.vim/brace.vim
autocmd FileType objc source ~/.vim/brace.vim
autocmd FileType java source ~/.vim/brace.vim
autocmd FileType pl source ~/.vim/brace.vim
endif
brace.vim is very simple, containing only the following line:
imap { {<CR>}<Esc>O
This causes typing a opening curly brace to immediately insert a Carriage Return character (equivalent to pressing return/enter) then inserts a closing curly-brace, then switching to command-mode and "typing" O to place an insert-mode cursor on a newly-inserted line above the closing curly-brace.
If anyone has a better way to do this, I'm open to suggestions.
1 comment:
I just use this for Perl:
inoremap { {<CR>}<Esc>O <TAB>
Post a Comment