How to indent a particular block of code in vim?
This question already has an answer here:
If vim knows the language you are using you can use the =
key to auto-indent a section of code.
Within the block type =a}
, or to auto-indent the entire file by typing gg=G
.
Use >i{
(right-shift inside current block), or better yet, =a{
(properly indent the current block), plus having a proper indent mode enabled (eg :set cindent
).
If you're opening up a whole file that's badly indented, you might want to start off with gg=G
(re-indent the whole file).
You can use:
set shiftwidth=2
to indent with two spaces, as I can see in your example, and then:
V
to insert in visual mode block,
j
to go one line down and select both,
>
to indent once
链接地址: http://www.djcxy.com/p/28614.html上一篇: 在vim中缩进
下一篇: 如何在vim中缩进特定的代码块?