是否可以使用VIM格式化C ++代码?

编程入门 行业动态 更新时间:2024-10-26 19:32:29
本文介绍了是否可以使用VIM格式化C ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对VIM比较陌生。我有一些源代码,这是一团糟。乍一看,我至少希望对代码有一个清晰而有条理的了解,所以我想对它进行正确的格式化,我的意思是缩进取决于函数的深度等等。

I am rather new to VIM. I got some source code and this is a mess. At a first sight I would like at least to get a clear and organised view of the code, so I like to get it rightly formatted, I mean indented depending on the depth of the functions and so.

我想知道是否可以使用VIM完成此操作,否则您可以推荐使用哪些其他命令行工具。

I wonder if it can be done with VIM, and otherwise which other commandline tools for that can you recommend.

谢谢

推荐答案

虽然vim是真正的瑞士刀,但我仍然偏爱使用外部工具来完成某些工作。与使用内置等效方法相比,这种方法有时更直观,更容易记住。

While vim is a true Swiss-knife I still prefer external tools for some jobs. This approach is some times much more intuitive and easy to remember than using the built-in equivalent.

在缩进的情况下,我通过astyle过滤了整个文件缓冲区。 astyle参数在几分钟之内就更容易掌握,尤其是如果您不是vim专家。同样,astyle在调整输出时也提供了更大的灵活性。

In the case of indenting, I filter the whole file buffer through astyle. The astyle parameters are much easier to grasp in a couple of minutes, especially if you are not a vim guru. Also astyle provides much more flexibility in fine-tuning the output.

首先安装astyle: #apt-get install astyle

First install astyle:# apt-get install astyle

然后在vim中: :%!astyle (简单的情况-astyle的默认模式是C / C ++) 或 :%!astyle --mode = c --style = ansi -s2 (ansi C ++样式,每个缩进级别使用两个空格) 或 :1,40!astyle --mode = c --style = ansi (ansi C ++样式,仅过滤1-40行)

Then inside vim: :%!astyle (simple case - astyle default mode is C/C++) or :%!astyle --mode=c --style=ansi -s2 (ansi C++ style, use two spaces per indent level) or :1,40!astyle --mode=c --style=ansi (ansi C++ style, filter only lines 1-40)

更多推荐

是否可以使用VIM格式化C ++代码?

本文发布于:2023-05-27 09:56:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/285743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   代码   VIM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!