tags:

views:

392

answers:

4

Hi,

Is there any way to make VIM put the brackets in the right indentation? For example, whenever I type:

if (something)
    do something

and then I hit enter after "do something", to have it jump back in line with the if statement? Also, when I go into insert mode, can I make it so it automatically jumps to the correct indentation level instead of staying at the beginning of the line?

Thanks.

+1  A: 
:set si

turns on smart indenting. You probably have to type control-D after a single line unbraced if like that, though.

Paul Tomblin
A: 

Add

set smartindent

to your .vimrc file

Adnan
+4  A: 

For general C like languages you can do this in .vimrc

set smartindent

However vim can do better (and does like you ask for C), by enabling specific rules for various languages. To enable that I have:

filetype on
filetype plugin on
filetype indent on

For more details search for "indent" in my .vimrc

pixelbeat
+2  A: 

I use set cindent, it does the right thing every time.

(But I'm not sure if the "right thing" for C/C++ is what you're asking about.)

Dan Olson