We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
变成这样
:
-prs
选项在括号周围放置空格,运算符周围和逗号后面的空格是标准的。-br
选项强制您的支撑样式,-i 4
使用 4 个空格来缩进。请注意,宏定义未修改,但代码中对类似函数的宏的调用是(大概是您想要的)。Turns this:
Into this:
The
-prs
option puts spaces around parenthesis, the spaces around operators and after the commas come standard. The-br
option enforces your bracing style, and-i 4
uses 4 spaces to indent. Note that the macro definition is not modified but the call to the function-like macro in the code is (presumably what you'd want).您可能需要查看 GNU 缩进。我相信它可以满足您正在寻找的一切。
You may want to look at GNU Indent. I believe it can do everything you're looking for.
Gnu Indent 或许可以做到这一点。不幸的是,缩进有大量选项,其中许多选项根本不直观,而且许多选项以极其奇怪的方式交互。我从来没有(甚至一次)设法让它以一种出来的方式不比进入的方式更难看的方式格式化代码。在某些情况下,它更统一。在其他情况下,我认为它确实是统一的,但它遵循的规则仍然很奇怪,以至于结果常常看起来很奇怪。
在与缩进斗争了一段时间后,我决定编写一个仅支持一种格式的更简单的程序会更容易,如果我想更改格式,只需编辑代码即可。
Gnu Indent can probably do that. Unfortunately, indent has a huge number of options, many of which aren't at all intuitive, and many of them interact in extremely strange ways. I've never (not even once) managed to get it to format code in a way that wasn't uglier coming out than going in. In some cases it was more uniform. In others I suppose it must really have been uniform, but the rules it was following were still strange enough that the result often just looked wierd.
After struggling with indent for a while, I decided that it was easier to write a much simpler program that only supported one format, and just edit the code if I wanted to change the format.
我使用 vim 与选项 cindent 和 formatoptions 取得了令人满意的效果。
你可以缩进整个文件,
你可能想写一个 formatexpr (vim7) 或
您可能想使用 s///g 命令编写自定义函数并将其映射到某个键。
下面将在括号后添加一个空格,除了 #define 行
v/#define/ s/[()]/\1 /g
是的,您将学习正则表达式:)
i had used vim with options cindent and formatoptions to a satisfactory effect.
you can indent a whole file by
you migh want to write a formatexpr (vim7) or
you might want to write a custom function with s///g commands and map it to a key.
the follwing will put a space after parantheses except in #define lines
v/#define/ s/[()]/\1 /g
yes, you will be learning regexes :)