坏消息
我不确定是否存在您建议的内容,尽管它肯定可以 - Vim 每天都让我感到惊讶。我敢肯定有人知道。
好消息
有更好的方法来实现你想要的!或者,我认为你想要什么。你可以告诉 Vim 对给定的文本区域执行格式化操作。您所要做的就是设置textwidth
您想要的最大宽度,然后用于gq{motion}
格式化移动的文本{motion}
。对于您的示例:
/* Line 1 of some large comment block,
hopefully it contains well written documentation. I'd
now like 'hopefully' to be on the first line.
*/
你只需设置一个合理的值textwidth
——这里看起来你要设置大约 50——然后格式化评论。将光标放在第一个上/
,然后
:set textwidth=50
gq%
抓住
但是等等,你说,那没用!
哎呀。你是对的。这里似乎发生的事情是 Vim 不理解这种格式。当我按照自己的指示进行操作时,我看到了这一点,尽管您的里程可能会有所不同:
/* Line 1 of some large comment block,
hopefully it contains well written
documentation. I'd now like 'hopefully' to be on
the first line.
*/
这看起来不对,事实并非如此。但是,如果我将您的块注释重新格式化为 Vim 识别的内容(这就是我编写块注释的方式),如下所示:
/*
* Line 1 of some large comment block,
* hopefully it contains well written documentation. I'd
* now like 'hopefully' to be on the first line.
*/
然后我gq%
(textwidth
仍然是 50)我得到:
/*
* Line 1 of some large comment block, hopefully
* it contains well written documentation. I'd now
* like 'hopefully' to be on the first line.
*/
这似乎奏效了。“现在”这个词也从第三行移到了第二行,但我认为这对 Vim 来说是一个很好的决定。还有一点需要注意:如果你不喜欢那些前导*
的 s,Vim 也会很好地处理这种格式:
/*
Line 1 of some large comment block,
hopefully it contains well written documentation. I'd
now like 'hopefully' to be on the first line.
*/
当我gq%
这样做时,我得到:
/*
Line 1 of some large comment block, hopefully
it contains well written documentation. I'd now
like 'hopefully' to be on the first line.
*/
有点好笑,但很有道理。在我看来更像是一个段落。希望这里的东西有用。
编辑:
正如 progo 在另一个答案中轻松提到的那样,您可以gqap
在我gq%
上面使用过的任何地方使用。谢谢!