Vim Auto Indent with newline

Zen picture Zen · Dec 18, 2010 · Viewed 42k times · Source

How do I get vim to place the cursor within the braces starting on a new line, ie with | denoting the cursor position :

class {
  |
}

right now with my settings it only does this

class {
|}

I got this in my .vimrc file set autoindent shiftwidth=2 tabstop=2 noexpandtab

Basically I just want how a normal IDE would indent it.

update:

I found how to do this with inoremap { {<CR>}<Esc>O

Answer

trkoch picture trkoch · Sep 27, 2012

I found that delimitMate does exactly what you describe and more (that is, automatically inserting the ending }). Note you have to tell delimitMate to expand carriage returns by adding let delimitMate_expand_cr=1 to your config.

From my observation, this is exactly the behaviour found in TextMate and SublimeText.