How to achieve better parenthesis matching / alignment in VIM?

Is there a way to make VIM brackets in the right recess? For example, whenever I type:

if (something) do something 

and then I press Enter after "do something" to return it to match the if statement. Also, when I go into insert mode, can I make it automatically go to the correct indentation level instead of staying at the beginning of the line?

+4
source share
4 answers

For common C-like languages, you can do this in .vimrc

 set smartindent 

However, vim can do better (and does the same thing you ask C) by including certain rules for different languages. To enable this, I:

 filetype on filetype plugin on filetype indent on 

More on finding "indent" in my.vimrc

+6
source

I use set cindent, it does everything right.

(But I'm not sure that the โ€œright thingโ€ for C / C ++ is what you ask for.)

+2
source
 :set si 

includes intellectual indentation. You may have to type control-D after one line is uncoupled, if possible.

+1
source

Add

 set smartindent 

to the .vimrc file

0
source

All Articles