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 {o}O
"
" Ydef insert "#define" at start of line
" ab Ydef 0i#define
"
" Yinc insert "#include" at start of line
" ab Yinc 0i#include
"
" Yelse insert else clause of if statement with following if statement
" ab Yelif else if () {o}k$2hi
"
" Yelse insert else clause of if statement
" ab Yelse else {o}O
"
" Yfor insert "for" statement
" ab Yfor for (;;) {o}kwa
"
" Yif insert "if" statement
" ab Yif if () {o}k$2hi
"
" Ywhile insert "while" statement
" ab Ywhile while () do {o}k$5hi
"
" Ymain insert "main" routine
" ab Ymain main (argc,argv) oint argc;ochar *argv;o{o}O
"
" insert brackets for statement list
" map o{o}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 { {}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 } /}/e+1i
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]