Vim - Formatting the code

1. The following Vim command will perform a fast code block formatting:
1G=G
We can split it up in simply says:
1G : Go to the first line(you can also use gg)
= : Indent according to the configuration
G : Go to the last line(tell Vim where to end indenting)

2. Another way is to go into visual mode with V and press =  to reindent the chosen lines.

3.
=i{ will reindent everything between { and } excluding the brackets.
other similar choices:
a{ : all the code between { and } including the brackets.
i(, a(, i<, a<, i[, a[

你可能感兴趣的:(Vim - Formatting the code)