URL:         http://www.math.fu-berlin.de/~guckes/vim/c.html
URL:         https://www.vim8.org/howto/c.html (mirror)
Created:     Sat Jun 22 00:00:00 MET DST 1996
Last update: Fri Jun 12 18:44:10 CEST 1998

VIM - C Editing

" ======================================================================== " Programming in C " ======================================================================== " " Ysbl insert statement block " ab Ysbl {<esc>o}<esc>O " " Ydef insert "#define" at start of line " ab Ydef <esc>0i#define " " Yinc insert "#include" at start of line " ab Yinc <esc>0i#include " " Yelse insert else clause of if statement with following if statement " ab Yelif else if () {<esc>o}<esc>k$2hi " " Yelse insert else clause of if statement " ab Yelse else {<esc>o}<esc>O " " Yfor insert "for" statement " ab Yfor for (;;) {<esc>o}<esc>kwa " " Yif insert "if" statement " ab Yif if () {<esc>o}<esc>k$2hi " " Ywhile insert "while" statement " ab Ywhile while () do {<esc>o}<esc>k$5hi " " Ymain insert "main" routine " ab Ymain main (argc,argv) <esc>oint argc;<esc>ochar *argv;<esc>o{<esc>o}<esc>O " " <c-a> insert brackets for statement list " map <c-a> o{<esc>o}<esc>O " Needs documentation, I know. :-)

Matching brackets

An opening bracket usually is matched by a closing one. So why not map the opening bracket to insert a closing one, too?

" Insert mode: Typing an opening curly bracket will insert a pair of " curly brackets and move the cursor before the closing curly bracket: :inoremap { {}<esc>i " Insert mode: Typing a closing curly bracket will jump after the next closing " curly bracket (this assumes that curly brackets are always inserted as a pair.) :inoremap } <esc>/}/e+1<c-m>i For inserting a single bracket without the specially mapped sequences simply quote them, ie precede them with a ^V.
Back to the -> VIM Home Page


Send feedback on this page to
Sven Guckes [email protected]