如何使用vim中的文件中搜索字符串`**`的所有出现?

发布于 2025-02-08 23:44:26 字数 102 浏览 1 评论 0原文

如何使用vim sike ** kwargs在文件中搜索**,当我使用/**时,它突出显示了整个文件。

How to search for ** in a file using vim like **kwargs , when I use a /** it highlights the entire file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装纯掩盖桑 2025-02-15 23:44:26

*是一个元字符,需要逃脱成为常规角色:

/\*\*

VIM将其称为“魔术”:如果模式为“魔术”,则需要逃脱元观念,如果它是“ nomagic”,您没有(这有点过分简化,请参见:help Magic)。

因此,您可以用\ m甚至“非常名义”将VIM强制将模式视为“ nomagic”,并使用\ v

/\V**

它无济于事,此处,但是……

关于为什么/**突出显示了整个缓冲区,可以在下找到提示:help/star/star

Exception: When "*" is used at the start of the pattern or just after
"^" it matches the star character.
  • 第一个*匹配缓冲区中的星星,
  • 第二个*匹配零或以上原子的零或更多原子,因此,本质上是每个字符。

* is a meta-character that needs to be escaped to become a regular character:

/\*\*

Vim refers to this as "magic": if the pattern is "magic", you need to escape meta-characters, if it is "nomagic", you don't (this is a bit over-simplified, see :help magic).

Therefore, you can force Vim to treat the pattern as "nomagic" with \M or even "very nomagic", with \V:

/\V**

Which doesn't help much, here, but well…

As for why /** highlights the whole buffer, a hint can be found under :help /star:

Exception: When "*" is used at the start of the pattern or just after
"^" it matches the star character.
  • The first * matches (at least some of) the stars in your buffer,
  • The second * matches zero or more of the preceding atom, as many as possible, so, essentially, every character.
爱你是孤单的心事 2025-02-15 23:44:26

您必须逃脱 *符号,尝试

/\*\*

在下面的文本上,我添加了额外的空间,以便更易于阅读

#不要使用这个
/ \* \*

You have to escape the * symbol, try

/\*\*

On the text below I added extra spaces to be easier to read

#Don't use this one
/ \* \*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文