Wednesday, June 18, 2008

Indentation in Vim

If you are a programmer, you always find doing indentations hard with
GUI based editors. But you can do indentations of line(s), block, or whole file,
with Vim with much ease and speed.

1. Indentation of a line.
a. Go to the line you want to indent.
b. Press ESc,
c. Press >>, to indent right, or
d. Press <<, to indent left

2. Indentation of n(say 5) lines.
a. Go to the first line of lines you want to indent.
b. Press ESc,
c. Press 5>>, to indent right, or
d. Press 5<<, to indent left


3. Indentation of a code block (Lines between { and }).
a. Go to the beginning '{' or end '}' of block.
b. Press ESc,
c. Press =%, to indent.


4. Indentation of whole program file.
a. Press ESc,
b. Go to the beginning of file by pressing 1G.
c. Press =G, to indent whole file.


I hope that now you can say that Vim is very easy and fast
as compared to other GUI editors. :) Happy VIMming.

Monday, June 9, 2008

Finding Matching Parenthesis in Your Source Code

Let us consider a simple C program.

1 #include

2
3 int main(int argc, char *argv[])
4 {
5 printf("Hello World.\n");
6 return (0);
7 }


In order to find matching parenthesis for parenthesis at line number 4.
Just press % in ESc mode.

You can use same command (%) to match (, ), [, ], {, or } .