In bash, autocompletion of paths has recently stopped working when issuing vim commands where the path is deeper than two directories (it continues to work as expected with other commands, such as ls and cd).

For example, if I type ls .config/btsync/bt and then press TAB, it expands to ls .config/btsync/btsync.conf.

If I type vim .config/bt and then press TAB, it expands to vim .config/btsync/.

However, if I type vim .config/btsync/bt and then press TAB, nothing happens (I would expect it to expand to vim .config/btsync/btsync.conf, as in the ls example, above.

I get the same issue when running as my own user and when running as su.

I read this post which mentioned an issue with older versions of bash-completion but I'm running 2.1-5.

UPDATE: After some additional testing, I've found that the root issue is that bash will only complete directory names, not filenames.

UPDATE: It turns out that bash-completion was the overall cause. See my second comment on the accepted answer.

Any suggestions as to the potential cause of this behaviour would be gratefully received!

  • Post your .bashrc! Jul 24, 2014 at 21:45
  • Link to my .bashrc posted, as demanded. Jul 25, 2014 at 9:25
  • Removed links to .bashrc, .aliases and .functions as not pertininent to the issue now that the cause has been discovered. Jul 26, 2014 at 10:29
  • same issue on Debian 9, some installations but not all :$ Nov 28, 2018 at 10:33

3 Answers 3


I did some more research for you and here is what I found - the key to autocompletion is the bash command complete. You can print the rules for vim using:

complete -p vim

Likewise you can remove these specific rules with:

complete -r vim

This command resets it to defaults - the usual paths and file names completion without any extra logic. That's probably what you want.

For more info check out help complete or man bash and look for the section about complete command (it's a bash built-in, hence it's documented in the bash manpage).

One last point - the above changes only affect the current bash session, if you want to remove the vim rules after every login put the complete -r vim to your ~/.bashrc.

Hope that helps :)

  • That did it. Many, many thanks. The complete -p vim command returned complete -F _filedir_xspec vim which was removed by the complete -r vim command, resolving the issue. I'm going to do some reading on the complete command and the information returned by the -p switch. Slightly puzzled why this behaviour changed so will investigate that, too. Jul 26, 2014 at 10:26
  • 3
    It seems as though bash-completion was the culprit after all. The _filedir_xspec function in /usr/share/bash-completion/bash_completion only completes directories. I've uninstalled bash-completion, removed the complete -r vim line from my .bashrc and rebooted and vim now behaves as expected. Jul 29, 2014 at 9:19

Bash by defaults autocompletes only path and file names. However the mechanism is extensible and bash can be taught to perform different autocompletion for different programs. For example for git it can autocomplete the sub-command names (clone, commit) and revisions instead of just pathnames. Sometimes it's handy, sometimes quite annoying - for example when gzip -d refuses to autocomplete filenames that don't have the .gz extension.

Bash completion is usually configured in /etc/bash_completion.d - you will probably find a file called vim in there. That's the file that contains the autocompletion rules for vim commandline.

Now you've got two options:

  1. Either fix the file to autocomplete paths as users probably expect anyway.
  2. Remove the file to disable the special vim rules and only perform the default path autocompletion.

And of course file a bug report that outlines the problem so that it gets fixed in the future versions :)

  • Many thanks for the great explanation :) I've had a look in /etc/bash_completion.d and there is only an hg file present (for Mercurial). Very strange. Jul 25, 2014 at 8:29
  • 1
    Then it must be elsewhere. Try /usr/share/bash-completion/ or list all the files from vim package or from bash or bash-completion packages (not sure how is it called on ArchLinux). It'll be there somewhere.
    – MLu
    Jul 25, 2014 at 8:58
  • 1
    Listing files from the bash-completion package shows /usr/share/bash-completion/completions does contain rules for many programmes, but not vim. Listing files installed with the vim package doesn't show any completion-related files and searching the whole system using find / -name vim also shows no completion-related files. Jul 25, 2014 at 9:22

Perhaps could you reinstall bash-completion : apt-get install --reinstall bash-completion

And have a look at file /etc/bash.bashrc : nano /etc/bash.bashrc

And verify that the following line are well uncommented:

if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion

Then, restart your terminal session

  • I tried removing bash-completion, testing the vim behaviour and then reinstalling bash-completion and testing but I still experienced the same problem in both circumstances. The lines you've listed are not present in /etc/bash.bashrc. This line is, however [ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion Jul 25, 2014 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .