How can I make it so that when I press C-xC-b to access the Buffer List that that buffer automatically takes focus instead of having to switch to it manually with C-xo? I can't find a variable that customizes this.
3 Answers
You can replace the command list-buffers which is run with C-x C-b to a function that does what you want. In this case buffer-menu-other-window opens the buffers list in another window with focus. Adding the following snippet to your init file should remap C-x C-b to the new function.
(define-key global-map [remap list-buffers] 'buffer-menu-other-window) Here global-map represents the keymap where C-x C-b is bound to a command, list-buffers the original command and buffer-menu-other-window the new command.
- 4Or
buffer-menu, if you don't want to use another window.Drew– Drew2014-10-08 02:07:05 +00:00Commented Oct 8, 2014 at 2:07 - Kudos for using remapping over global-set-key.user66– user662018-06-22 21:47:37 +00:00Commented Jun 22, 2018 at 21:47
- @metaturso You can remap with
global-set-keyas well:(global-set-key [remap list-buffers] #'buffer-menu-other-window).global-set-keyis merely a thin wrapper arounddefine-key.Basil– Basil2018-06-23 10:58:31 +00:00Commented Jun 23, 2018 at 10:58
An alternative is to switch to ibuffer, which does not share this problem.
ibuffer is part of GNU Emacs, so on recent versions of Emacs you should just need to add
(global-set-key (kbd "C-x C-b") 'ibuffer) to your init file.
- 1This is what I do as well, but the wording of your answer makes it seem like it is more than just a matter of preference.nispio– nispio2014-10-08 14:15:21 +00:00Commented Oct 8, 2014 at 14:15
-
Here's what I use:
(add-to-list 'display-buffer-alist '((derived-mode . Buffer-menu-mode) (display-buffer-reuse-mode-window display-buffer-same-window))) As mentioned by others, switching to ibuffer is also an option.