Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 192010
 

Code formatting and indentation in VIM

Answer:

Vim support code formatting and auto indentation - if you tell Vim to know the filetype (either by file extension, or by setting the filetype)

e.g. A simple C program (test.c)


#include 

main()
{
for(int i=0;i<10;i++)
{ 
printf ("Hello World!\n");
}
}

Then type following in Vim command mode (by pressing Esc):

gg=G

Now the code will be formatted to:

#include 

main()
{
    for(int i=0;i<10;i++)
    {
        printf ("Hello World!\n");
    }
}

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>