I found a Vim auto pair plugin called vim-autoclose. It works great just like other IDEs. For example, when you type {
it gives you {|}
(the "|" represents the cursor). Then, if you press "Enter", the {|}
becomes:
{
|
}
This is what I need, but unfortunately it disables my Chinese input method application,so I have to abandon it.
I have tried other autoclose plugins, but none of them can auto close in this way. I found a way to make auto close work like the way above.
:autocmd FileType c,java,javascript ino <buffer> { <C-G>u{<CR>}<Esc>O<C-T>
But it has a problem with the shiftwidth. For example, if I :set shiftwidth=4
the new line between {}
will have an 8 space indent. The indent in the new line doubles the shiftwidth.
My question is how to set the indent of the new line to the same space indent of shiftwidth?