Find a file (via recursive directory search) in Vim

vim find file in project
vim find file autocomplete
vim fuzzy search
vim file explorer
vim open file
vim search project for string
vim fzf
vim file navigation

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?

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

:e **/test/

will open test/ 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.

Find files in subdirectories | Vim Tips Wiki, Vim offers several commands for searching for files by name: :find, :sfind, :tabfind on Vim will directly open the first file found in your 'path' matching "filename". Notice, the search is done in a recursive manner, and you can use wildcards. Tip 1234: Find files in subdirectories, for when the contents of a file are not known, but the file name or part of the file name is. Tip 1008: Toggle to open or close the quickfix window , for a quick way to toggle on or off the quickfix window which contains the results of your vimgrep searches.

There is a find command. If you add ** to your path then you can search recursively.

:set path

will show you your current path, add ** by doing something like

:set path=.,/usr/include,,**

the bit before the ** I copied from the initial :set path

then you can just type

:find myfile.txt

and it opens magically!

If you add the set command to your .vimrc it'll make sure you can do recursive search in future. It doesn't seem to search dot directories (.ssh for example)

Searching for files | Vim Tips Wiki, Using Vim to find words in all files shouldn't be difficult, yet multi-file you can search through all your files recursively from the current directory  Vim offers several commands for searching for files by name: :find, :sfind, :tabfind on the command-line, several normal-mode commands like gf, and others. If you just enter :find filename, Vim will directly open the first file found in your 'path' matching "filename".

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.


How to Search in Multiple Files Using Vim, Vim's answer is the :find command, which allows us to recursively search our project directory for a file by its filename. You can usually  It’s not a surprise that there is a built-in way to find in files in VIM. You can use four commands: :grep, :lgrep, :vimgrep, :lvimgrep. :grep will use the default “find” tool for your operating system (“grep” for linux family, “findstr” for Windows). :vimgrep will use built-in vim search (same as for “/” searching)

vim as a builtin find command (:help find) but only open the first found file. However you can use this amazing plugin : FuzzyFinder which does everything you want and even more

Navigating project files with Vim by Arjan van der Gaag, You can add ** to your path: set path+=**. This way it will find every file recursively based on your current directory. But apparently it's not  Open all .c or .h files in the directory (and it's subdirectories) two directories up from the current directory: args ../../**/*.[ch] The only caveat (and it's a major one) is that it's very slow. There's also the :Explore **/[pattern] command, available via netrw.vim. Example: :Explore **/*.vim

Command-T lets you find a file very fast just by typing some letters. You can also open the file in a new tab, but it need vim compiled with ruby support.

vimscript to search recursively in parents directory for the existence , This page shows how to search and find words in vi or vim text editor running on a Linux or Unix-like systems. To search using Vim/vi, for the current word: Let us open a file named demo.txt in the current directory: Search and open file from the CLI. The vi / vim text editor supports running any : command using the following syntax: To open file and go to function called main(), enter: Next open file and go to line number 42, enter: See “VI / VIM: Open File And Go To Specific Function or Line Number” for more info.

Access a file under subdirectories of a path through gf command, Let's go back to our data-shell directory on the Desktop and use ls -F to see Using the shell to create a directory is no different than using a file explorer. many programmers use Emacs or Vim (both of which require more time to No matter what editor you use, you will need to know where it searches for and saves files. The above example will search any folder in the C:\ drive beginning with the word Folder. So if you have a folder named FolderFoo and FolderBar PowerShell will show results from both of those folders. The same goes for the file name and file extension. If you want to search for a file with a certain extension, but don't know the name of the

How to find a Word in Vim or vi text editor, A :grep with ripgrep is orders of magnitude faster than :vimgrep. All of the The ** allows you to do recursive search for the pattern in all text files in subfolder. For years I always used variations of the following Linux find and grep commands to recursively search subdirectories for files that match a grep pattern: find . -type f -exec grep -l 'alvin' {} \; This command can be read as, “Search all files in all subdirectories of the current directory for the string ‘alvin’, and print the filenames

Working With Files and Directories – The Unix Shell, But I would like search in all the files insed directory. try it out. It searches recursively from current directory all files ending with .tcl and containing the string student. To search in current directory only, just use *.tcl.

  • related…
  • @E_Jovi what does 吊 mean?
  • @CiroSantilli巴拿馬文件六四事件法轮功 I mean your name.. which express something forbidden in China.
  • @E_Jovi but what does 吊 mean? Just to improve my Chinsese :-)
  • @CiroSantilli巴拿馬文件六四事件法轮功 As commendatory term, it mean you do something while most other people can't, in this case, I think that your name tell truth of history but most chinese can't do it because of government's behaviour, as derogatory term, it express that person speak or behave in a way that shows lack of respect for a person.
  • +1 I never tried the wildcard in edit command. That works really well with the wildmode as well. So you can type :e **/Suite<tab> and all have the list of possible files
  • I, in turn, had not tried wildmode with wildcard expansion. I updated my answer with a mention.
  • Be very careful with large file collections with complex directory structure. This command can hang your vim for very long time. With my codebase it's been searching for 20 minutes already. What complicates matters is that there is no way to stop it. I tried the usual Ctrl+C and Ctrl+Break. Procmon shows that vim is still searching for my file. So the solution is not for everyone :(
  • @evpo I had the same problem. I solved it by giving the first part of the path in the search to reduce the number of folders :e dir/**/ Then it took less than a second.
  • how the crap did I not know about this? I've been using vim for more than 20 years. Just amazing 👏🏼👏🏼👏🏼
  • If the file name is very long, this method isn't very comfortable, or does it do my*.txt also?
  • Yes, you can use * wildcard. see :h find.
  • You can also append to your path by doing :set path+=**