Search code examples
vimindentation

Vim Auto Indent with newline


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


Solution

  • Put this in your .vimrc :

    imap <C-Return> <CR><CR><C-o>k<Tab>
    

    Assuming autoindent and smartindent are set correctly, typing Ctrl + Return between braces will put your cursor where you want it to be.