How can I autoformat/indent C code in vim?

后端 未结 9 2465
青春惊慌失措
青春惊慌失措 2020-11-29 14:20

When I copy code from another file, the formatting is messed up, like this:

fun()
{
for(...)
{
for(...)
{
if(...)
{
}
}
}
}

How can I autof

9条回答
  •  情歌与酒
    2020-11-29 14:58

    I like indent as mentioned above, but most often I want to format only a small section of the file that I'm working on. Since indent can take code from stdin, its really simple:

    1. Select the block of code you want to format with V or the like.
    2. Format by typing :!indent.

    astyle takes stdin too, so you can use the same trick there.

提交回复
热议问题