在使用TeleScope.nvim时,如何在搜索结果中包含特定的隐藏文件/文件夹?
我正在使用neovim和望远镜作为查找器(find_files,live_grep,file_browser),默认情况下,望远镜忽略了.gitignore中包含的隐藏的文件和文件 - 我如何添加异常(例如.gitlab -ci file/fileser)到此列表中?因此,除了.gitlab-ci文件/文件夹外,望远镜仍然会忽略隐藏的文件?
I'm using neovim and Telescope as a finder (find_files, live_grep, file_browser), by default Telescope is ignoring hidden files and files included in .gitignore - how can I add exception (e.g. .gitlab-ci file/folder) to this list? so Telescope will still ignore hidden files except .gitlab-ci file/folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
望远镜使用
ripgrep
以搜索文件。默认情况下,
ripgrep
忽略了几组文件,包括隐藏的文件(dotfiles)和git忽略的文件。添加- NO-EIGNORE-VCS
和- 隐藏
标志将使它浏览这些文件。可以通过
defaults.vimgrep_arguments
来配置RIPGREP
的参数。在您的情况下,要搜索不在
中的隐藏文件
。望远镜配置:
AS
- 隐藏
将通过全隐藏文件启用搜索,您可能需要查看.ignore
或.rgignore
文件。他们告诉ripgrep
在搜索过程中要忽略哪些文件。参见Telescope uses
ripgrep
to search through files. By default,ripgrep
ignores several groups of files, including hidden files (dotfiles) and files ignored by git. Adding--no-ignore-vcs
and--hidden
flags will make it to search through those files.Arguments for
ripgrep
can be configured viadefaults.vimgrep_arguments
.In your case, to search through hidden files, which are not in
.gitignore
--hidden
flag should be added:You can always test the command from the terminal before changing the Telescope configuration:
As
--hidden
will enable search through all hidden files, you might want to look into.ignore
or.rgignore
files. They tellripgrep
which files to ignore during search. Seeripgrep
's documentation for more info.使用像这样的默认过滤器忽略模式:
我知道你可以在某人的 vimrc 文件或 望远镜文档。但可能对一些新手有帮助。
Use default filter ignore pattern like this:
I know you can find this in someone's vimrc files or telescope docs. But may help some newbies.
我还在搜索一种配置,该配置使我在使用望远镜插件时可以在隐藏文件中搜索/中。解决方案的核心是使用
ripgrep
带有
-G/ - - -glob
参数。允许我的简单配置,看起来如下:
I was also searching for a configuration that would allow me to search for/in hidden files while using telescope plugin. The core of solution is to use
ripgrep
with-g / --glob
parameter.The simple config that allowed me this, looks like following:
经过数周的激烈阅读和测试,我发现了最简单的解决方案在这里。
为了找到隐藏的文件,我将以下行添加到
.config/nvim/init.vim
:启动neovim ui时,按
fff
弹出望远镜<代码> find_file 屏幕,然后按ffh
时,您可以搜索隐藏的文件。要在
live_grep
中搜索隐藏的文件,工作要困难得多。从我的角度来看,最优雅的解决方案是首先创建以下
.config/nvim/lua/find_hidden.lua
:将以下几行添加到您的
init.vim :
总结一下:使用
find_hidded.lua
文件和init.vim
中的以下行telescope_find_files
和telescope_live_grep
:After several weeks of intense reading and testing, I have found the for me easiest solution here.
In order to find HIDDEN FILES, I have added the following lines to
.config/nvim/init.vim
:When you launch Neovim UI, pressing
fff
pops up the Telescopefind_file
screen, and when you pressffh
, you can search for HIDDEN files.To search for hidden files in
LIVE_GREP
, the work was a bit more difficult.From my perspective, the most elegant solution is to first create the following
.config/nvim/lua/find_hidden.lua
:The add the following the following lines to your
init.vim
:To sum it up: with the
find_hidden.lua
file and the following lines in yourinit.vim
, you can easily search for hidden and non-hidden files both intelescope_find_files
andtelescope_live_grep
:经过一番痛苦和磨难后,我阅读了
telescope.txt
帮助,并打算在find_files
和live_grep
中显示隐藏文件:find_files
When运行
find_files
,使用 Vimscript 中提供的no_ignore
选项(帮助)。live_grep
但是对于
live_grep
我们需要传递additional_args
选项,该选项(如果我错了请纠正我)仅在 Lua 中可用(帮助)。-u
标志是一个rg
标志,用于显示被忽略的文件。注释
我想你可以在设置中影响这些
,如果有人评论说我会将它们添加到我的答案中。我个人需要为每个键映射,所以这是我的
lazy.nvim
键配置:我希望处理文件过滤器的接口允许您指定这些:
After much pain and suffering, I've read the
telescope.txt
help and maanged to show hidden files in bothfind_files
andlive_grep
:find_files
When running
find_files
, use theno_ignore
option, available in Vimscript (help).live_grep
But for
live_grep
we need to pass theadditional_args
option which is (correct me if I'm wrong) only available in Lua (help).The
-u
flag is anrg
flag that shows ignored files.Some notes
I guess you can affect these in the settings, if someone comments that for both I'll add them to my answer.
I, personally, need to have a keymap for each, so here's my
lazy.nvim
keys config:I wished interfaces that dealt with file filters would let you specify these:
我的解决方案是使用
.ignore
文件。根据文档,您可以创建规则忽略 ripgrep 默认值。我有一个充满隐藏文件的 git 存储库,我希望将其包含在搜索结果中,因此.ignore
如下所示:首先,我包含存储库中的所有文件。然后我再次删除
.git
目录。现在我的所有点文件都显示在 Telescope 中。My solution was to use a
.ignore
file. According to the docs, you can create rules that ignore the ripgrep defaults. I have a git repo full of hidden files that I would like to include in the search results, so the.ignore
looks like this:First, I include all the files in the repo. Then I remove the
.git
directory again. Now all my dot files are shown in Telescope.