在 Vim 中查找文件(通过递归目录搜索) [英] Find a file (via recursive directory search) in Vim
问题描述
有没有办法在 Vim 中递归搜索目录中的文件(需要时使用通配符)?如果不是本机,是否有可以处理此问题的插件?
Is there any way to search a directory recursively for a file (using wildcards when needed) in Vim? If not natively, is there a plugin that can handle this?
推荐答案
您可以在 :edit
命令中使用通配符.所以,
You can use wildcards with the :edit
command. So,
:e **/test/Suite.java
将打开 test/Suite.java,无论它在当前目录层次结构中的哪个位置.这适用于制表符完成,因此您可以在打开文件之前使用 [tab] 扩展通配符.另请参阅 wildmode 选项,以浏览所有可能的扩展名.
will open test/Suite.java no matter where it is in the current directory hierarchy. This works with tab-completion so you can use [tab] to expand the wildcards before opening the file. See also the wildmode option for a way to browse through all possible extensions instead.
另一个技巧是使用
:r! find . -type f
将当前目录中所有文件的列表加载到缓冲区中.然后,您可以使用所有常用的 vim 文本操作工具来导航/排序/修剪列表,并使用 CTRL+W gf
在新窗格中打开光标下的文件.
to load a list of all files in the current directory into a buffer. Then you can use all the usual vim text manipulation tools to navigate/sort/trim the list, and CTRL+W gf
to open the file under the cursor in a new pane.
这篇关于在 Vim 中查找文件(通过递归目录搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!