In Emacs, how do I select the completion list with the keyboard?
Asked Answered
O

2

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.

Occidental answered 6/8, 2013 at 15:11 Comment(1)
See my suggestion in the edit to my answer below.Teador
T
12

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.

Teador answered 6/8, 2013 at 16:22 Comment(4)
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.Occidental
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 -qTeador
You may have M-v bound to some other function.Teador
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.Occidental
K
2

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

Kopeisk answered 6/8, 2013 at 15:15 Comment(2)
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?Occidental
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 TABing in the minibuffer until a unique result is obtained, with the completion buffer acting only as a visual reference.Bluebonnet

© 2022 - 2024 — McMap. All rights reserved.