使用vim。我的原始文件如下:
Wire 1_blah
Wire 2_blah
Wire 3_blah
reg blah_blah_1
reg blah_blah_2
reg blah_blah_3(除了,想象一下大约4000行)
因此,我想要的是:
Wire 1_blah
Wire 2_blah
reg blah_blah_1
reg blah_blah_2
Wire 3_blah
reg blah_blah_3意思是,我想删除所有行与数字3,并粘贴在它们的末尾。我尝试了以下几点:
:'<,'>g/3/d然后
p但这只记得最后一行被删除了。
对于如何快速有效地完成这一任务,有什么建议吗?我不想浪费时间手工操作。
谢谢!
发布于 2014-05-15 08:12:17
:g/3/m$做你想做的事:
:g[lobal]/foo/command在每一行匹配的foo上执行command,:m$将当前行移动到缓冲区的末尾,:g/3/m$将包含3的所有行移动到缓冲区的末尾。见:help :global和:help :move。
为胜利而执行命令!
编辑
若要在同一寄存器中删除所有这些行,请使用“寄存器a”:
:g/3/d A意思是“剪切并追加这些行来注册a”。
见:help registers。
发布于 2014-05-15 08:08:44
如果您查看:help :g,您将看到一个在匹配项上执行正常命令的选项。下面的命令将按找到的顺序将每一行移动到底部。
:g/3/normal ddGp从:help :g复制的文档。
To repeat a non-Ex command, you can use the ":normal" command: >
:g/pat/normal {commands}
Make sure that {commands} ends with a whole command, otherwise Vim will wait
for you to type the rest of the command for each match. The screen will not
have been updated, so you don't know what you are doing. See |:normal|.发布于 2014-05-15 08:27:58
我不知道在输出示例中是否需要那些空行。如果没有,其他的答案对你有效。如果您真的想要这些空行,这一行适用于您:
:g/3/exec "normal! DGo\<esc>p"https://stackoverflow.com/questions/23672475
复制相似问题