vim - 在 Vim 中轻松将函数参数重新格式化为多行

特别是在编辑遗留 C++ 代码时,我经常发现自己手动重新格式化如下内容:

SomeObject doSomething(firstType argumentOne, secondType argumentTwo, thirdType argumentThree);

到这样的事情:

SomeObject doSomething(firstType argumentOne,
                       secondType argumentTwo,
                       thirdType argumentThree);

是否有内置命令来执行此操作?如果没有,有人可以建议一个插件或提供一些 VimScript 代码吗? (Jgq 可以很容易地反转这个过程,所以它不需要双向。)

最佳答案

您可以使用 splitjoin .

SomeObject doSomething(firstType argumentOne, secondType argumentTwo, thirdType argumentThree);

在括号内或括号上,键入 gS 进行拆分。你得到:

SomeObject doSomething(firstType argumentOne,
    secondType argumentTwo,
    thirdType argumentThree);

您也可以使用vim-argwrap

https://stackoverflow.com/questions/12733909/

相关文章:

bash - UNIX 统计时间格式

formatting - 引用 YAML(对于 Travis CI)

java - 是否可以在 Eclipse 中将部分 java 代码标记为不自动格式化?

python - 设置 ipython 的默认科学记数法阈值

r - 如何在不丢失行名和列名的情况下对 R 中的平面列联表进行子集化?

.net - 如何在格式字符串中指定自定义千位分隔符

asp.net-mvc - 电话号码或社会保险号的 DisplayFormat.DataFormat

floating-point - 如何格式化具有特定精度和前置零的 f32?

eclipse - 如何配置 Eclipse 格式化程序在字段声明之间不插入空行?

formatting - 使用 LaTeX Beamer 将引文文本放在同一张幻灯片上