Get Vim to open new blocks like Sublime Text 2

advertisements

In sublime text 2 when you:

BLOCK { <Return>

It generates (where the pipe is the cursor):

BLOCK {
  |
}

How can I get Vim to behave this way?

I have autoindent on, and smartindent off because with smartindent it does this on return:

BLOCK {
 |}

To be more clear, I'm specifically looking for 2 returns, moving up a line, and tabbing in (2 soft tabs to be specific). I already have it auto-matching characters like {, (, [ etc.


A simple mapping will work for most purposes:

imap {<cr> {<cr>}<c-o>O

Depending on plugins, some users may need inoremap instead of imap.