gpt4 book ai didi

vim - 移动与 :g to the top of the file 匹配的行

转载 作者:行者123 更新时间:2023-12-02 06:10:44 26 4
gpt4 key购买 nike

我有一个很大的文本文件,其中包含对特定函数 method_name 的多次调用。

我使用 :g/method_name 来匹配它们。

如何将它们移动到文件顶部(第一个匹配项位于顶部)?

我尝试了 :g/method_name/normal ddggP 但这颠倒了顺序。有没有更好的方法直接按顺序剪切并粘贴所有匹配行?

输入文件示例:

method_name 1
foo
method_name 2
bar
method_name 3
baz

示例输出文件:

method_name 1
method_name 2
method_name 3
foo
bar
baz

最佳答案

尝试相反的方法如何:将不匹配的行移到底部:

:v/method_name/normal ddGp

这似乎达到了你想要的。

关于vim - 移动与 :g to the top of the file 匹配的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6553963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com