-1

我有一个包含多行的文本文件。

test = 
more text more text more text more text
more text more text more text more text
... etc....
more text more text more text more text
more text more text more text more text
1 text
test2 =
more text more text more text more text
more text more text more text more text
3 more text

ETC

我想要做的是从一个数字开始向上移动行,并在找到的第一行(向后)以 '=\s' 结尾之后附加它们

预期输出:

test = 1 text
more text more text more text more text
more text more text more text more text
... etc....
more text more text more text more text
more text more text more text more text
test2 = 3 more text
more text more text more text more text
more text more text more text more text

我不知道该怎么做。
有人能帮我吗?

4

2 回答 2

4

使用:global,:norm:move使用搜索作为 Ex 命令目标的可能性:

:g/^\d/m?.*=$|norm kJ

分解:

:g/pattern/command " executes command for every line matching pattern
^\d                " pattern for "lines that start with a number"
m?.*=$             " move matched line to right below the first
                   " line ending with = upward
|                  " separator between Ex commands
norm               " execute normal mode command
kJ                 " go to line above and join
于 2013-09-23T14:45:43.120 回答
2

宏可以帮助...

/^\d<cr>:.m?=<cr>kJ

简短说明:

/^\d   " find line beginning with number
:.m?= " move current line under the previous line with (=)
kJ     "move cursor back to the line with (=), and join the next

它的工作方式如下:

(截图里好像又打了一个?,最后一个n,但我不会再录了。)

在此处输入图像描述

于 2013-09-23T14:41:31.823 回答