题
假设我在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>
我坚持如何指定 <the text that is 4 lines below this line>
部分。
我尝试了类似的东西 .+4
(当前行以下4行),但无济于事。
解决方案
您可以使用Blockwise剪切和粘贴进行操作。
1)在每条“重命名”线的开头插入空间,例如 :5,7s/^/ /
2)使用块视觉选择(ctrl-v
)选择所有“文件”行,然后按 d
删除它们
3)再次使用块视觉选择在所有更名线的开始时选择空间字符,然后按 p
. 。这将粘贴从您删除的块中的相应行粘贴到每行的开始。
其他提示
:1,3:s/\ze\n\%(.*\n\)\{3}\(.*\)/ \1
解释:
\ze - end of replaced part of match - the string matched by the rest of the pattern will not be consumed
\n - end of current line
\%(.*\n\)\{3} - next 3 lines
\(.*\) - content of 4th line from here
这将使后来的线路留在那里。
我真的会为此做一个宏。删除下行,向上移动,粘贴, J
OIN行,然后在其他线上运行宏。我认为另一种合适的方法是一个单独的脚本,可以充当过滤器。
不隶属于 StackOverflow