vi / vim Auto complete File Name While Editing Files

Q. I use vi / vim as IDE (Integrated development environment) a software development system using Ubuntu Linux. How do I auto complete file name under vim / vi text editor while editing text file or java / c / python program? I can auto complete file nameunder bash shell by hitting [TAB] key.

A. Yes, it is quite frustrating when you are not able to open files immediately. There is no need to add any special command for this task. All you have to do is press [Tab] key to complete directory or file names just like bash command. For example, while coding html file, if you would like to open email.php, just type following (ESC + : + em + hit [TAB] key):
:e em[TAB]
To auto complete directory name again hit [TAB]:
:cd /e[tab]
For further information see help page, by typing following command:
:help path
This works with vim version 6.1 and above. If you are using old version add following to your ~/.vimrc file:
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
Save and close the file. Then when you type ,e in normal mode you can use tab to complete to the file.


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • Frazer Kirkman Jan 31, 2009 @ 12:09

    thanks for the tip.

    its also worth mentioning that
    set nocompatible
    will make this work.

    Not sure what versions this is apllicable to

  • rc3 Nov 9, 2009 @ 3:12

    Nice tips. Thanks and keep up with the good works.

  • joce Sep 21, 2011 @ 13:33

    I believe the question was about doing it in EDIT mode, when you type e.g.

    #include “mycppheader.h”

    and you want auto-completion of this.

    It is possible in vim, check e.g. http://www.vim.org/scripts/script.php?script_id=169

    • joce Sep 21, 2011 @ 13:44

      found it.
      Ctrl-X Ctrl-F will complete a filename.

      • gpgdx Nov 21, 2011 @ 8:38

        Exactly what I was looking for… great!

      • sai Apr 23, 2014 @ 10:11

        Thanks. This is what I was looking for. I think just Ctrl+F will work.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum