删除突出显示文本的行/删除突出显示的文本
有谁知道如何删除:
- 突出显示文本的行
- 所有突出显示的文本自身
(突出显示的文本(搜索后的pe)不是选定的文本)
是否有一个命令可以搜索所有突出显示的文本并删除该行? (与我用来突出显示文本的搜索命令或函数无关)
g/pattern/d
命令并不总是删除突出显示的文本
pe /^\(.*\)\(\n\1\)\+$
-->突出显示所有双线
但是g/^\(.*\)\(\n\1\)\+$/d
-->不删除所有双线
Does anyone know how to delete:
- lines with highlighted text
- all highlighted text self
(highlighted text (p.e. after a search) not selected text)
Is there a command which search all highlighted text and delete the line?
(independent which search command or function I used to highlight text)
the g/pattern/d
command does not always delete the highlighted text
p.e. /^\(.*\)\(\n\1\)\+$
--> highlight all double lines
but g/^\(.*\)\(\n\1\)\+$/d
--> does NOT delete all double lines
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,您可以这样删除搜索到的模式:
您可以这样删除包含搜索到的模式的整行:
Well, you can delete the searched pattern this way:
And you can delete the whole line with the searched pattern this way:
除了 sixfeetsix 的答案 :
的行,请输入:g!//d
或:v//g
:g/
之后输入
,请输入:g/
CTRL-r//d
插入搜索寄存器的内容 (CTRL-r/
表示将/
) 注册到正在键入的命令中。In addition to sixfeetsix' answer:
<pattern>
, type:g!/<pattern>/d
or:v/<pattern>/g
<pattern>
after:g/
, type:g/
CTRL-r//d
which inserts the content of the search register (CTRL-r/
means register/
) into your command being typed.来自这个超级用户的回答:
From this SuperUser answer:
您可以使用搜索和替换(替换)来执行此操作。
它通常是这样使用的:
更具体地说,将搜索结果替换为空(以将其删除):
省略末尾的
c
以替换所有内容而不进行确认。输入
:help :s
了解更多信息。要删除整行,您可以进行替换,只需将整行与正则表达式匹配 (
%s/^.*your_search_here .*\n//g
),或者您可以使用多次重复(多次重复)功能。它通常如下使用:
更具体地说,将其与用于删除行的普通命令 (
d
) 结合起来:键入
:help :g
以获取更多信息。提示:
在进行替换之前正确获取查询的一个简单方法是在命令模式而不是默认模式下进行搜索。
而不是:
键入:
然后您可以进入命令模式 (
:
),按向上键调出上次搜索,然后编辑该行以将其转换为替代项。You could use search-and-replace (substitute) to do this.
It is generally used like this:
More specifically, replace your search results with nothing (to remove them):
Omit the
c
at the end to replace all without confirmation.Type
:help :s
for more info.To delete whole lines, you could either do a substitute, and just match the whole line with a regular expression (
%s/^.*your_search_here.*\n//g
), or you could use the multiple repeats (multi-repeat) feature.It is generally used like this:
More specifically, combine it with the normal command you use to delete a line (
d
):Type
:help :g
for more info.Tips:
An easy way to get your query right before doing your substitute is to do your search in command mode rather than the default mode.
Instead of:
Type:
Then you can go to command mode (
:
), hit the up key to bring up your last search, and edit the line to convert it to a substitute.我想这本质上是同一个问题:
Vim:使用 \_ 跨多行匹配字符串时。在正则表达式中,yank 命令仅适用于第一行
这看起来像是 Vim 中的一个错误。
I guess it's the essentially the same question as this:
Vim: when matching string across multiple lines using \_. in regex, yank command only works for the first line
It looks like a bug in Vim.