我有以下案文:
A simple line
TITLE1:
Another usual line
TITLE2:
More usual lines here
TITLE3:
Last line of this sample text.
我想将上面的内容转换为:
A simple line
TITLE1:
Another usual line
TITLE2:
More usual lines here
TITLE3:
Last line of this sample text.
因此,我希望删除标题行后面的空行,而是在标题行之前添加空行。标题行都由标识,以':'结尾。
我试着遵循下面的代码
:%s/(.+):\r/\n\1:/g
但不起作用。
发布于 2017-12-13 08:51:13
如果我正确理解您的需求,我将使用:g//{cmd}
而不是:s/../../
:
g/:$/norm JO
如果不希望在:
之后有空格,请在J
之前添加一个g
说明:
:g/pat/norm JO
pat
匹配的行,执行普通模式命令J
和O
。J
确实加入了,意思是“删除”下一个中断行。O
在当前行之前添加一个空行。您可以将光标移动到TITLE
行上,按JO
查看会发生什么。
如果您需要进一步的解释/细节,请阅读:
:h :g
:h :norm
:h J (or :h gJ)
:h O
发布于 2017-12-14 02:39:19
:g/TITLE/ m+1
它怎麽工作?
: ............... command
g ............... global
/TITLE/ ......... all lines with TITLE
m+1 ............. move to the next line
https://stackoverflow.com/questions/47798270
复制