If I

M-x shell
C-u M-x shell <RET>

I get two buffers, named *shell* and *shell*<2>.

If I switch to another buffer, and I do

C-x b sh <TAB>

The echo area doesn't complete to *shell* (which is unambiguous at this point), it completes to shell*. I then have to

C-a * <RET>

in order to switch to it. I really dislike this. Is there a way to get the former to complete to *shell*, so that I can do

C-x b sh <TAB> <RET> <RET>

Rather than being forced into

C-x b sh <TAB> C-a * <RET>


What I'm really after is just an easier way to switch to the buffer named *shell* than the current way, so suggestions here would also be welcome.


I recommend ido-mode. It changes how completing-read works, adding an inline display of possible matches, and adding several extra keyboard commands for manipulating the list. There are quite a lot of them, but the one I use most frequently is probably C-s, which cycles the current list of matches so that the next one is selected.

In your example, C-x b sh would match both shell buffers, and hitting enter would select the first one in the list (which would be whichever one you used most recently) and hitting C-s would cycle that list to select the next one.

Additionally, if you customize ido-enable-flex-matching then it won't require that what you type be an exact substring. You'll be able to type sh2 and have it match *shell*<2>. I use this all the time.

Edit: While I was poking around in the source code, I noticed that you can customize the variable completion-category-overrides to change how the default completing works. It's a little complicated, and the help strings aren't readily available in the customization interface as I'd prefer, but you should be able to figure it out. C-h v completing-styles-alist will take you to the variable that holds information about the styles, which includes the help strings. It'll be easier to read them if you use the source link to jump to the file they're in, since the indentation will be better and it'll have syntax highlighting. Perhaps one of these styles will suit you better than the default. I still prefer ido-mode though.

  • Any idea of why it doesn't complete to *shell*? – extremeaxe5 Jun 28 '19 at 16:36
  • Which? completing-read in vanilla Emacs, or completing-read with ido-mode? – db48x Jun 30 '19 at 4:22
  • The one in vanilla emacs. If it completed to just *shell* I wouldn't have this problem. – extremeaxe5 Jun 30 '19 at 5:06
  • I haven't examined the commit history for this code, but I suspect that it's simply an oversight. An explanation probably won't fit into a comment... – db48x Jun 30 '19 at 19:25
  • In fact, further testing suggests that I don't quite understand the exact behavior; I thought that try-completion was doing this, but it isn't. Anyway, you can use M-x report-emacs-bug to send a bug report to the mailing list where the Emacs developers will see it. – db48x Jun 30 '19 at 19:59

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.