我可以使用 vim “star” 搜索 PHP 类成员和方法吗? 搜索?

发布于 2024-07-08 21:47:25 字数 672 浏览 4 评论 0原文

vim * 星号/星号搜索 (:help star) 是一个很棒的功能,它可以让您找到光标所在单词的下一个出现位置。 不幸的是,它将美元前缀视为字符串的一部分,因此,如果我在类名中的“SearchTerm”上方按 *,它会在注释中找到“SearchTerm”,以及“$this->SearchTerm”,但不会找到“$ SearchTerm”:

class SearchTerm 
{
    /* do something with SearchTerm */

    var $SearchTerm;

    function DoStuff() 
    {
         return $this->SearchTerm;
    }
}

有没有办法告诉明星搜索忽略 $ 前缀?

只是为了扩展Haes答案:

我需要从iskeyword中删除$

:set iskeyword         # iskeyword=@,48-57,_,192-255,$

:set iskeyword-=$      # remove the $ as an acceptable word character

The vim * star / asterisk search (:help star) is a great feature which lets you find the next occurrence of the word the cursor is over. Unfortunately it treats dollar-prefixes as part of the string, so if I press * while over the "SearchTerm" in the class name it finds "SearchTerm" in the comment, and "$this->SearchTerm", but not "$SearchTerm":

class SearchTerm 
{
    /* do something with SearchTerm */

    var $SearchTerm;

    function DoStuff() 
    {
         return $this->SearchTerm;
    }
}

Is there a way of telling star search to ignore the $-prefix?

Just to expand on Haes answer:

I needed to remove $ from iskeyword

:set iskeyword         # iskeyword=@,48-57,_,192-255,$

:set iskeyword-=$      # remove the $ as an acceptable word character

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

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

发布评论

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

评论(2

北陌 2024-07-15 21:47:25

实际上,在 Mac 上使用 vim 7.2,星号搜索完全按照您希望的方式工作。

编辑:检查您的“iskeyword”(:set iskeyword)设置为什么,因为星级搜索基于此选项来查找单词搜索词。

或者,您可以使用 'g*' (:help gstar) 来部分搜索光标所在的单词。

希望这能有所帮助。

Actually using vim 7.2 on Mac, star search exactly works as you would like it to do.

EDIT: Check what your 'iskeyword' (:set iskeyword) is set to because star search is based on this option to find the word search term.

Alternatively, you could could use 'g*' (:help gstar) to get a partial search for the word the cursor is over.

Hope this helps somehow.

蓝眼睛不忧郁 2024-07-15 21:47:25

您应该能够通过在 $ 前面放置反斜杠来转义它: \$

You should be able to escape the $ by placing a backslash before it: \$

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