Bash autocomplete with vim command

arch linuxautocompletebashvim

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!

Best Answer

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 :)

Related Question