Search code examples
bashvimtab-completion

Tab completion ignoring some files in Bash/Debian


I am using tab completion in a standard Debian install with Bash and I have some files being ignored. For example, if I have the files:

index.php
index.php.a

If I type vim i then tab it immediately selects "index.php " (see space after file name). Normally, it would just complete up to "index.php" and give me the option to type something else after.

Why is it behaving differently in this situation?

Update

Some commands such as "cp" seem to handle the tab completion just fine, so maybe it is vim looking for specific file extensions?


Solution

  • The bash-completion package uses the function _filedir_xspec to complete vim. That function in general completes filenames, but excludes certain patterns depending on which command it is completing.

    For vim, the exclusion pattern starts like this:

    _install_xspec '*.@([ao]|so|so.!(conf|*/*) ...
    

    I.e., among other things, files ending in .a should be ignored. The thinking behind that is probably that these are often created as backup copies and you probably don't want to edit them.

    If you want to override this behaviour, you can add your own completions into ~/.bash_completion; for example, to get vim to complete on all filenames, use this:

    complete -f vim
    
    

    which will make vim tab completion default to the built-in file completion bevahiour.