获取不同行的文本,在 Vim 中使用 ex
假设我在 Vim 中有以下文本:
file1.txt
file2.txt
file3.txt
renamed1.txt
renamed2.txt
renamed3.txt
我想要如下转换:
file1.txt renamed1.txt
file2.txt renamed2.txt
file3.txt renamed3.txt
我的想法类似于以下内容:
:1,3 s/$/ <the text that is 4 lines below this line>
我一直不知道如何指定
部分。
我尝试过类似 .+4
(当前行下方 4 行)但无济于事。
Let's say I have the following text in Vim:
file1.txt
file2.txt
file3.txt
renamed1.txt
renamed2.txt
renamed3.txt
I want a transformation as follows:
file1.txt renamed1.txt
file2.txt renamed2.txt
file3.txt renamed3.txt
What I have in mind is something like the following:
:1,3 s/$/ <the text that is 4 lines below this line>
I'm stuck with how to specify the <the text that is 4 lines below this line>
part.
I have tried something like .+4
(4 lines below the current line) but to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用分块切割和分块切割来做到这一点。粘贴。
1) 在每个“重命名”行的开头插入空格,例如
:5,7s/^/ /
2) 使用分块视觉选择 (
ctrl-v
) 进行选择所有“file”行,然后按d
删除它们3) 再次使用块视觉选择来选择所有重命名行开头的空格字符,然后按
p
>。这会将您删除的块中的相应行粘贴到每行的开头。You can do it with blockwise cut & paste.
1) insert space at the start of each "renamed" line, e.g.
:5,7s/^/ /
2) Use blockwise visual selection (
ctrl-v
) to select all the "file" lines, and pressd
to delete them3) use blockwise visual selection again to select the space character at the start of all the renamed lines, and press
p
. This will paste the corresponding line from the block you deleted to the start of each line.解释:
这会将后面的行保留在原来的位置。
explained:
This will leave the later lines where they are.
我真的会为此制作一个宏。删除下面的行,向上移动,粘贴,加入行,然后在其他行上运行宏。我认为合适的另一种方法是一个单独的脚本来充当过滤器。
I would make a macro for this really. Delete the lower line, move up, paste,
J
oin lines, then run the macro on the others. The other method I think would be appropriate is a separate script to act as a filter.