Find a file (via recursive directory search) in Vim

后端 未结 15 1022
感情败类
感情败类 2020-12-22 18:42

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?

相关标签:
15条回答
  • 2020-12-22 19:11

    vim has bild in commands named grep, lgrep, vimgrep or lvimgrep that can do this

    here is a tutorial on how to use them http://vim.wikia.com/wiki/Find_in_files_within_Vim#Recursive_Search

    you can also use an external command like find or grep from vim by executing it like this

    :!find ...
    
    0 讨论(0)
  • 2020-12-22 19:12

    I'd recommend ctrlp.vim. It's a very good plugin, ideal to work inside large projects. It has search by file name or full path, regexp search, automatic detection of the project root (the one with the .git|hg|svn|bzr|_darcs folder), personalized file name exclusions, and many more.

    Just press <c-p> and it will open a very intuitive pane where you can search what you want:

    It's possible to select and open several files at once. It also accepts additional arbitrary commands, like jump to a certain line, string occurrence or any other Vim command.

    Repo: https://github.com/kien/ctrlp.vim

    0 讨论(0)
  • 2020-12-22 19:17

    You can use wildcards with the :edit command. So,

    :e **/test/Suite.java
    

    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.

    Another trick is to use

    :r! find . -type f
    

    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.

    0 讨论(0)
提交回复
热议问题