12

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.

programking
  • 7,064
  • 9
  • 41
  • 62
Chris
  • 699
  • 3
  • 13
  • 3
    This is purely editorial, but I have never understood how having the list come up un-focused is supposed to be useful. So yeah, good question. – Avdi Oct 08 '14 at 03:12

2 Answers2

10

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.

Vamsi
  • 3,916
  • 22
  • 35
  • 4
    Or `buffer-menu`, if you don't want to use another window. – Drew Oct 08 '14 at 02:07
  • Kudos for using remapping over global-set-key. –  Jun 22 '18 at 21:47
  • @metaturso You can remap with `global-set-key` as well: `(global-set-key [remap list-buffers] #'buffer-menu-other-window)`. `global-set-key` is merely a thin wrapper around `define-key`. – Basil Jun 23 '18 at 10:58
8

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Dave
  • 121
  • 2