Score:0

Can I get better tab completion in terminal?

cn flag

Say I have three files with filenames beginning with s in a folder.

If I type s and hit Tab, I get the error ding sound and nothing completes in the terminal. I have to type out enough of the filename to make it unambiguous to terminal which file I want before it autocompletes with Tab.

So if I have filenames school, scuba, and scary, and I want to open school, I have to type sch or else it won't autocomplete. I have seen examples where you type s and then you can Tab through all of the options one by one.

Is this feature unavailable or do I have to change a setting somewhere?

Score:4
vn flag

I believe I have configured exactly the solution you're after. For this to work in Bash, add this line to your /etc/inputrc (for global setting) or ~/.inputrc for your user only):

"\e[Z": menu-complete

This line will make it so when you hit Shift+Tab, it cycles through possible solutions for what you have typed.

So for instance, if you're in a directory with 3 files starting with s, typing echo s and hitting Shift+Tab will cycle through the 3 of them.

I find this shortcut particularly useful when doing systemctl status .., where I only have to type sctl st (I have an alias), and then double Tab to cycle to status.

I found that it's best to still hang on to regular Tab behaviour, since there are situations where you'll still want to make it display possible completions on double Tab.

Also, please note that if you just start typing a filename, the autocomplete will also look at filenames in your PATH.

So if you just type the beginning of a filename s and hit Shift+Tab, it will cycle through filenames in your current directory along with your PATH. That's just how the PATH works.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.