如何将所有匹配的行拖入一个缓冲区? [英] How do I yank all matching lines into one buffer?

查看:12
本文介绍了如何将所有匹配的行拖入一个缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将所有匹配的行拖入缓冲区?

How do you yank all matching lines into a buffer?

给定一个文件:

match 1
skip
skip
match 2
match 3
skip

我希望能够发出一个命令,将与模式匹配的所有行(本例中为/^match/)拖入单个缓冲区,以便我可以将其放入另一个文档、摘要或其他内容中.

I want to be able issue a command to yank all lines that match a pattern (/^match/ for this example) into a single buffer so that I can put it into another doc, or into a summary or whatever.

命令应该在缓冲区中结束:

The command should wind up with this in a buffer:

match 1
match 2
match 3

我的第一个想法是尝试:

My first thought was to try:

:g/^match/y

但我刚拿到最后一场比赛.这是有道理的,因为 :g 命令有效地为每个匹配的行重复 y.

But I just get the last match. This makes sense, because the :g command is effectively repeating the y for each matching line.

也许有一种方法可以将 yank 附加到缓冲区,而不是覆盖它.我找不到.

Perhaps there is a way to append a yank to buffer, rather than overwriting it. I couldn't find it.

推荐答案

:help registers
:help quote_alpha

指定一个大写字母作为注册名以附加到它,例如:yank A.

Specify a capital letter as the register name in order to append to it, like :yank A.

这篇关于如何将所有匹配的行拖入一个缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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