How to autocomplete filenames in sub-directories when opening them for editing using e.g. :e </path/to/file>?

When opening files in sub-directories for editing using e.g. :e </path/to/file>, I often press TAB multiple times to autocomplete file and/or directory names.

My problem is that using TAB for auto-completion, I cannot move into the targeted subdirectory. Instead subsequent TABs return filenames in the current directory cyclically.

By pressing <space> and deleting it again after having auto-completed the targeted sub-directory, I'm able to move into the sub-directory and autocomplete filenames in that directory.

Is there a smarter way to move into a sub-directories when TAB'ing for filename auto-completion?

Targeted sub-directory: watchdog_io

Targeted file in sub-directory: io.py

enter image description here

2 Answers 2


Don’t do the 'path' trick. The 'path' option affects many of vim’s best navigational techniques.

Instead (and I only learned about this recently—see :help 'wildmenu'), when you’re dealing with directories:

  • use Down to “drill down” into the subdirectory and start completing filenames below
  • use Up to “move up” into the parent directory and complete filenames above
  • use your 'wildchar' to cycle in the current directory (as you’ve already noted)
  • Thanks, what do you mean by wildchar - do you mean TAB? Can you refer to a specific :help page?
    – Shuzheng
    Commented Mar 9, 2020 at 19:10
  • In my case, both <down> and <up> works for drilling down the sub-directory, however, I cannot seem to move up into the parent directory.
    – Shuzheng
    Commented Mar 9, 2020 at 19:15
  • @Shuzheng see :help 'wildchar' for that—it defaults to <Tab>. For the rest, see 'wildmenu'
    – D. Ben Knoble
    Commented Mar 9, 2020 at 20:01

Put this in your .vimrc:

set path+=**

This will also search in all subdirectories.

Then use the :find command. Start writing a part of the filename, for example...

:find io

...and then when you press Tab, it will autocomplete or offer possible matches from which you can choose. It will find io.py even if it's in a subdirectory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.