vimtricks.wiki Concise Vim tricks, one at a time.

How do I find a file by name in Vim's path and open it in a new tab?

Answer

:tabfind {name}

Explanation

:tabfind is the tab-aware counterpart to :find. It searches all directories in Vim's path setting for a file matching {name} and opens the result in a new tab page rather than the current window. This gives you a clean way to navigate to project files without disturbing your current split layout.

How it works

  • Vim searches each directory listed in 'path' in order until it finds a match
  • Wildcards are supported: :tabfind main* finds the first file starting with main
  • Tab completion works on the filename argument (after setting up path correctly)
  • Typically paired with set path+=** in your vimrc to enable recursive project-wide search

Example

With set path+=** in your config and a project like:

project/
  src/
    auth.go
    main.go
  tests/
    auth_test.go

From anywhere in the project:

:tabfind auth.go

Opens src/auth.go in a brand new tab page.

Tips

  • :find opens in the current window; :sfind opens in a horizontal split; :tabfind opens in a new tab
  • Use <Tab> completion with :tabfind to browse matches without knowing the exact path
  • Combine with set wildmenu and set wildmode=list:longest for an interactive completion menu
  • For fuzzy matching by partial name use :tabfind *auth*

Next

How do I extract regex capture groups from a string in Vimscript?