在 Vim 中轻松地将函数参数重新格式化为多行 [英] Easily reformatting function arguments onto multiple lines in Vim

查看:16
本文介绍了在 Vim 中轻松地将函数参数重新格式化为多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Particularly when editing legacy C++ code, I often find myself manually reformatting something like this:

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

像这样:

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

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

Is there a builtin command to do this? If not, can someone suggest a plugin or provide some VimScript code for it? (J or gq can reverse the process very easily, so it need not go both ways.)

推荐答案

你可以使用 splitjoin.

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

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

Inside or on brackets, type gS to split. You get:

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

你也可以使用 vim-argwrap

这篇关于在 Vim 中轻松地将函数参数重新格式化为多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆