gpt4 book ai didi

search - Ag.vim : Use word under the cursor as *part* of a search pattern?

转载 作者:行者123 更新时间:2023-12-02 04:22:09 26 4
gpt4 key购买 nike

使用 Ag.vim 插件,您可以通过调用 :Ag 轻松搜索光标下的单词没有任何参数,但如何将光标下的单词包含为搜索模式的一部分?我正在尝试在 vimrc 中添加一些内容来搜索 Ruby 文件中的方法定义。像这样的东西:

autocmd FileType ruby noremap K :Ag! "\bdef <C-R><C-W>\b"<CR>

它无法识别 <C-R><C-W> 。另外,我已经尝试过 \b\< , \>作为单词边界。 Ag用途\b在 Vim 上下文之外,但我知道它会翻译 \<\>\b在某些情况下(但不确定这种情况)。

最佳答案

我通常用一招,按*即可在你当前的单词上然后使用 :AgFromSearch ,您可以指定具体路径,例如 :AgFromSearch /any/path/

如果您确实想将单词作为搜索模式的一部分,您可以使用 <cword> (当前词)

 nmap  <silent> <D-f> :Ag "def <cword>" /any/path/<CR>   

关于search - Ag.vim : Use word under the cursor as *part* of a search pattern?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24580278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com