首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SpaceVim搜索项目中所有目录(和子目录)中的所有文件中的文本

使用SpaceVim搜索项目中所有目录(和子目录)中的所有文件中的文本
EN

Stack Overflow用户
提问于 2021-11-16 18:45:05
回答 1查看 200关注 0票数 2

所以我开始使用Neovim/Spacevim,它太棒了!

我还在适应所有的东西,因为我以前从来没有用过Vim或者类似的东西。

我的问题围绕着在当前打开的项目的所有文件中搜索特定文本。

我正在使用nerdtree文件管理器,我想知道如何在项目中的所有文件中搜索特定的字符串。例如,如果我想在当前打开的文件夹/目录中搜索function thisExactFunction(),我该如何着手呢?主要目标是拥有包含此搜索字符串的所有文件的列表。

我安装了fzf (以及ripgrep),但在所有文件中搜索特定文本似乎有困难。我只能搜索文件本身,或者其他不能产生我需要的内容的搜索。

谁能给我指个方向……?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-16 19:57:54

查看Fzf提供的Ggrep命令-查看此series of vim screencasts了解如何使用vim的内置功能(快速修复列表填充为:vimgrep)通过其他grepping工具实现相同的功能。

自定义函数

我的.vimrc中有一个函数,它使用ag silver searcher在一个目录(以及任何子目录)中搜索所有文件。所以如果你安装了ag,这应该是可行的:

代码语言:javascript
复制
" Ag: Start ag in the specified directory e.g. :Ag ~/foo
function! s:ag_in(bang, ...)
    if !isdirectory(a:1)
        throw 'not a valid directory: ' .. a:1
    endif
    " Press `?' to enable preview window.
    call fzf#vim#ag(join(a:000[1:], ' '),
                \ fzf#vim#with_preview({'dir': a:1}, 'right:50%', '?'), a:bang)
endfunction

" Ag call a modified version of Ag where first arg is directory to search
command! -bang -nargs=+ -complete=dir Ag call s:ag_in(<bang>0, <f-args>)

奖金

有时在vim的帮助中很难找到东西,所以我也有一个函数,可以使用上面的函数来交互式地搜索帮助文档。这可以很好地研磨你想要的主题。使用:H实现此功能(与经典的:h相反)

代码语言:javascript
复制
function! Help_AG()
    let orig_file = expand(@%)
    let v1 = v:version[0]
    let v2 = v:version[2]
    " search in the help docs with ag-silver-search and fzf and open file
    execute "normal! :Ag /usr/share/vim/vim".v1.v2."/doc/\<CR>"
    " if we opened a help doc
    if orig_file != expand(@%)
        set nomodifiable
        " for some reason not all the tags work unless I open the 'real' help
        " so get whichever help was found and open it through Ag
        let help_doc=expand("%:t")
        " open and close that help doc - now the tags will work
        execute "normal! :tab :help " help_doc "\<CR>:q\<CR>"
    endif
endfunction

" get some help
command! H :call Help_AG()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69994544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档