如何在 vim 中自动格式化/缩进 C 代码? [英] How can I autoformat/indent C code in vim?
本文介绍了如何在 vim 中自动格式化/缩进 C 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从另一个文件复制代码时,格式很混乱,像这样:
When I copy code from another file, the formatting is messed up, like this:
fun()
{
for(...)
{
for(...)
{
if(...)
{
}
}
}
}
如何在 vim 中自动格式化这段代码?
How can I autoformat this code in vim?
推荐答案
尝试以下按键:
gg=G
说明:gg
到文件顶部,=
是修复缩进的命令,G
告诉它执行操作到文件末尾.
Explanation: gg
goes to the top of the file, =
is a command to fix the indentation and G
tells it to perform the operation to the end of the file.
这篇关于如何在 vim 中自动格式化/缩进 C 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文