7

When I tab-complete in a minibuffer and Emacs displays a completion list in a new buffer, how do I switch to that buffer without using the mouse?

I tried C-x o, but that just switched to the first buffer, out of which I entered the minibuffer.

I also tried C-x b, but that gives me command attempted to use minibuffer while in minibuffer.

Lastly I tried C-x <C-right>, which gives me cannot switch buffers in minibuffer window.

EDIT: I spoke about minibuffer completion in my example, but being able to access the completion list (using the keyboard) from within a regular buffer is also important to me, and not working. The M-v shortcut was suggested, but it only seems to work inside the minibuffer accessed by M-x, in every other buffer I've tried, M-v is bound to scroll down command and does not switch to the completion list. I doesn't even seem to work in other minibuffers. For example, it doesn't work in the shell command minibuffer invoked by M-! either.

bug
  • 515
  • 1
  • 5
  • 17

2 Answers2

11

You can use M-v (documented here) which switches to the completion buffer and puts the cursor on the first completion:

Typing M-v, while in the minibuffer, selects the window showing the completion list (switch-to-completions). This paves the way for using the commands below. <PageUp> or <prior> does the same. You can also select the window in other ways...

EDIT: It looks like based on your edit to the original question that what you're asking for is a way to switch to the completions buffer more globally. There is a function switch-to-completions that selects the completions list - you might consider binding that function to a key of your choosing, e.g.:

(define-key global-map (kbd "C-x t") 'switch-to-completions)

For example, such a binding allows me to switch to completions from "Shell command: " invoked by M-!, and places the cursor on the first possible completion.

Keith Flower
  • 4,032
  • 25
  • 16
  • Weirly enough, this does not seem to work for me. (I'm using Emacs v24.2.1 btw.) When I press `M-v` in the minibuffer it just says `Beginning of buffer` and doesn't select the completion list. – bug Aug 06 '13 at 16:40
  • Odd. What about pressing `PageUp` - that should work as well (on my Mac that's `fn-Up`). You might try restarting Emacs without reading your initialization file, ie `emacs -q` – Keith Flower Aug 06 '13 at 17:07
  • You may have `M-v` bound to some other function. – Keith Flower Aug 06 '13 at 17:13
  • It works when I enter the minibuffer with `M-x`, however it does not work when I try to access the completion list from other minibuffers like `M-!` or from any "normal" buffer. – bug Aug 13 '13 at 09:55
2

You can use C-xo twice, or use M--C-xo, which switches to the previous buffer instead of the next one.

choroba
  • 231,213
  • 25
  • 204
  • 289
  • `C-x o` twice does not work, because the first command closes the completion list. Applying a negative argument to the buffer switch command however does work well. I'd use `C-- C-x o` though. Also, it does not insert the cursor at the first completion, but the beginning of the buffer, which sucks because I then have to move all the way down. Is this really how people use completion? – bug Aug 06 '13 at 15:24
  • 1
    bug: No, I suspect that very few people actually interact directly with the completion buffer. The normal approach is simply to continue filtering the options by typing and `TAB`ing in the minibuffer until a unique result is obtained, with the completion buffer acting only as a visual reference. – phils Aug 06 '13 at 19:13