The first thing to do is to set the automatic indentation before you set the parentheses automatically, by adding the following statement to the ~/.VIMRC file:
set Autoindentset shiftwidth=4set TabStop=4set Expandtabset smarttab
The parentheses in the VI editor cannot be indented automatically, and I find that using IMAP is possible, and after the experiment, when the indentation is set to the above, my curly brace indentation is set to:
IMAP {<cr> {<cr>}<esc>o
It means to map curly braces to line breaks in curly braces when you enter them. Enter the curly braces to connect the uppercase O, think, replace the content is you can use a manual line of input, again, according to this idea, if you want the brackets and parentheses auto-complete and the cursor moved to the middle of the parentheses, You can use the following mapping methods:
IMAP [[]<esc>Iimap (()<esc>i
Think about, [] plus I is not your own operation when you can use an input method, according to this idea, we can also map:
IMAP [[]<left>IMAP ()<LEFT>
This looks more intuitive, enter an opening parenthesis, equivalent to enter the full parenthesis and then move the cursor to the left one character
And then what is IMAP mean, IMAP means the mapping operation in the Insert mode, the mapping rules of the above settings only work in the input mode, there is no such mapping rule in other modes there will be no substitution of this input, map has several mapping modes, want to set a pattern mapping rules , you can use the mapping command in this mode, such as command mode CMAP, Normal mode nmap, about the map mode can refer to this blog http://haoxiang.org/2011/09/vim-modes-and-mappin/
VI Vim Bracket Auto indent settings and explanations