Apologies if this is a duplicate, but I'm (unsuccessfully) trying to edit the bash completion options for vim.

Specifically, when editing a LaTeX document, there are lots of supplementary files which I don't want to edit with vim. i.e. I only want to edit .tex files, not .aux, .pdf and other files that are generated when compiling a document.

I've played around with the complete command, but am not having much joy..

Why does the following command not remove .aux files from the list of generated file names?

$ complete -o default -X '^.*aux' vim

The pattern you want is not a regex, it is a bash glob and you need the -f to tell it you are completing files. Also you don't want default for -o since this will add in the filenames you just filtered out, either drop the option or choose something different (I have used dirnames so that it also completes directories). The following should do the job:

complete -f -o dirnames -X '*.@(aux|pdf)' vim

The relevant man page quote for the glob used:

If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Composite patterns may be formed using one or more of the following sub-patterns:

                 Matches zero or one occurrence of the given patterns
                 Matches zero or more occurrences of the given patterns
                 Matches one or more occurrences of the given patterns
                 Matches one of the given patterns
                 Matches anything except one of the given patterns

extglob should already be enabled by bash completion, but if not you need to do this also.

  • Thanks for pointing out that the pattern is a bash glob, but this unfortunately still fails to remove .aux files from the completion list... Using homebrew's bash 4.3.30 on Mac OS X btw, if that makes a difference... – Alex Leach Dec 29 '14 at 12:13
  • 1
    @Alex, updated. – Graeme Dec 29 '14 at 12:35

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.