Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

This question has an open bounty worth +100 reputation from xralf ending in 7 days.

The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.

3  
the expression db/migrate/*crea is not a regular expression. the * character here is used as a bash expansion wildcard. –  Mircea Vutcovici May 1 '12 at 17:51
    
Which OS, distribution and version and which bash version do you use? –  Cyrus 9 hours ago

2 Answers 2

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
*TAB*
[user@host foo]$ vim bar/foo1 
[user@host foo]$ touch bar/bar1
[user@host foo]$ vim bar/*1
*TAB* *TAB*
[user@host foo]$ vim bar/*1
bar1/ foo1  

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

share|improve this answer
1  
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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