I want to modify the existing vi bash autocompletion rule to exclude some filenames (for example, the config.log file). I tried using the FIGNORE environmental variable, but that didn't work. Using the complete builtin overrides the existing rule, rather than modifying it.

Is there any way to do this?

  • @MarkPlotnick Overwriting data in /usr/share/ doesn't sound clever to me. Instead a modified definition of _install_xspec () should be put in ~/.bashrc and ~/.bash_profile. Nov 9 '14 at 0:17

To exclude uninteresting filenames or extensions from bash completion, add this line to your .bashrc file:


You can see the current configuration with

complete -p vi
complete -o bashdefault -o default -o filenames -o nospace -F _exp_ vi

and the definition of the used shell function with

type _exp_

There is a complete feature / option -X which allows to filter the results. The problem is that this applies only to to complete actions. It does not apply to the -o default results (I don't know about -o bashdefault).

You can change the compspec:

complete -d -f -o filenames -o nospace -F _exp_ -X '@(config.log|config.doc)' vi


  1. you can have only one -X in the complete call (former ones are overwritten)

  2. you need shopt -s extglob for the above to work; otherwise you are limited to a single name or pattern ("*.log")

  • 1
    That worked, thanks. I wish there was a better way to do it. Nov 9 '14 at 1:08
  • @MatthewCline Try my solution below. It worked for me. Dec 15 '16 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.