Auto brackets and indent in VIM

February 23rd, 2009

As I mentioned in post gedit + plugins = \o/ you can make gedit auto complete {}, insert proper indentation and place the cursor in the right position.

I have recently moved on to using VIM. Of course I want the same functionality, and therefore had to make this happen!

Here is what you do:

In your ~/.vimrc put:

set autoindent
inoremap {<CR> {<CR>}<Esc>O<Tab>

Enjoy!

Edit:
If you want auto completion for “([])” etc. you might want to check out autoclose.vim!

Edit 2:
If you want the automatic indentation inside {} while using autoclose.vim you need to remove “{“,”}” from the source.

Line 148 then look like:

let s:charsToClose = {'(': ')', '[': ']', '"': '"', "'": "'"}