如何将 grep 结果存储在 Vim 的缓冲区中? [英] How to store grep results in a buffer in Vim?

查看:30
本文介绍了如何将 grep 结果存储在 Vim 的缓冲区中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试一个进程,因此我将strace附加到进程并将输出重定向到一个文件,然后执行操作.在这个过程中,它创造了很多过程.所以这就是我想要做的,我想选择一个进程执行的所有系统调用.为此,我使用了模式为 pid 的 grep 命令:

I want to debug a process, hence I attached strace to the process and redirected the output to a file and then performed the operation. During the process it has created a lot of processes. So here is what I want to do, I want to select all the system calls executed by a process. To do that I used grep command with pattern as pid:

:grep pid %

它显示了结果,但我无法遍历结果,它提示

It shows the result but I am not able to traverse through the result, it promts

Press ENTER or type command to continue

并返回到文件.我想做的是将结果存储在缓冲区中,然后查看它,如果需要,将其保存到文件中,否则将其丢弃并返回到原始文件.有没有办法在不退出 vim 编辑器的情况下做到这一点?提前致谢.

and returns to the file. What I would like to do is store the result in a buffer and then have a look into it and if required save it into a file or else discard it and return to the original file. Is there a way to do this with out exiting from the vim editor? Thanks in advance.

我想搜索结果并将其存储在缓冲区中.

I would like to search with the result and store that in a buffer.

推荐答案

您可以转到较早的搜索,然后轻松返回:

You can go to older searches, and back easily:

:copen
:colder " goes to older
:cnewer " newer

您可以使用 lvimgrep(使用位置窗口)进行另一次搜索:

You can have another search using lvimgrep (uses location window):

:lopen
:lnext
etc...

它也有历史:

:lolder
:lnewer

您可以读入任何缓冲区:

You can read into any buffer:

:r!grep bla **/*.cs

最后,任何提供输出的命令都可以使用 redir 命令重定向:

Finally, any command that gives output, can be redirected with the redir command:

:redir >> file
:grep bla **/*.cs
:redir END

有关使用它的多种方法(重定向到寄存器或变量),请参阅 :he redir.

See :he redir for the many ways to use it (redirect into registers or variables).

这篇关于如何将 grep 结果存储在 Vim 的缓冲区中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆