Autocomplete filenames


Vim can autocomplete filenames and paths from insert mode. Just press <ctrl-x> <ctrl-f>. You’ll have to autocomplete each segment of the file path one at a time, but you can make quick work of this by repeating this key mapping several times in succession without leaving insert mode. After each segment, press <ctrl-n> and <ctrl-p> to move and down the list of matches.

  • <ctrl-x> <ctrl-f> – Autocomplete filename and file path segments
  • <ctrl-n> – Move down through the autocomplete match list
  • <ctrl-p> – Move back up through the autocomplete match list

It’s easiest to demonstrate so I’ve put together a demo on our YouTube channel. Watch:

When might this be useful? The most obvious use that comes to mind is require statements. If you’re writing code that references other libraries under your current working directory, this is a quick way to include them without typing out the full path. Another place I use them regularly is when linking between markdown files in a directory of notes. What do you use filename completion for? Let us know! Send us an email or comment on the post.

How useful was this tip?

Average rating 4.2 / 5. Vote count: 64

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts