How can I enable tab completion in bash for a statement such as vim db/migrate/*crea? Essentially I am looking for tab completion to match the regular expression and present the options.

How would one go about doing this?

This questions relates to one I asked here

  • 4
    the expression db/migrate/*crea is not a regular expression. the * character here is used as a bash expansion wildcard. May 1 '12 at 17:51
  • Sure it's a regular expression. It matches db/migrate///////crea. :-)
    – ghoti
    Oct 24 '14 at 21:43

What version of bash are you using? For me with 4.1.2, it seems to work out of the box on CentOS 6.2:

[user@host foo]$ cd /tmp/foo
[user@host foo]$ mkdir bar
[user@host foo]$ touch bar/foo{1,2,3}
[user@host foo]$ vim bar/*1
[user@host foo]$ vim bar/foo1 
[user@host foo]$ touch bar/bar1
[user@host foo]$ vim bar/*1
[user@host foo]$ vim bar/*1
bar1/ foo1  

Are you making sure to tap TAB twice for the auto-completion list?

  • 4
    This has more to do with your Bash completion scripts than it has to do with your version of Bash.
    – ephemient
    May 2 '12 at 0:26

show-all-if-ambiguous makes pressing tab once (instead of twice) show all completions. It also changes the way globs are completed:

$ touch 1.0.{1,2}
$ bind 'set show-all-if-ambiguous off'
$ open *0* # I pressed tab twice here, and *0* was kept as *0*
1.0.1  1.0.2
$ open *0*^C
$ bind 'set show-all-if-ambiguous on'
$ open *0* # I pressed tab once here, and *0* was replaced with 1.0.
1.0.1  1.0.2
$ open 1.0.

glob-complete-word (\eg) would also complete *0 (without a wildcard at the end) to 1.0.. It also works with patterns like */file* and **/file.

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.