Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get better bracket matching/alignment in VIM?

Tags:

vim

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?

like image 331
victor Avatar asked Jan 23 '23 19:01

victor


1 Answers

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

like image 198
pixelbeat Avatar answered Jan 28 '23 05:01

pixelbeat