52

In GNU emacs, every time I hit Ctrl-x Ctrl-b to see all of my buffers, the window is split to show the buffer list, or if I have my window already split in 2 (for instance, I will have a shell running in the lower window), the buffer list appears in the other window.

My desired behavior is for the buffer list to appear in my active window so that I can select the buffer I want and continue to working in the same window, rather than having to Ctrl-x Ctrl-o to the other buffer, selecting the buffer (with enter) and editing that buffer in the other window... I've googled for it but it doesn't seem to be a common desire? I wonder if anyone has an elispy (or other) solution?

dbr
  • 165,801
  • 69
  • 278
  • 343
hatmatrix
  • 42,883
  • 45
  • 137
  • 231

9 Answers9

66

You might want to rebind C-x C-b to invoke buffer-menu rather than list-buffers:

(global-set-key "\C-x\C-b" 'buffer-menu)
itsjeyd
  • 5,070
  • 2
  • 30
  • 49
zimbu668
  • 1,295
  • 10
  • 12
  • 2
    I wanna know if there is way that you can use the short key such as 1, 2,... or a, b, c...to open one buffer more quickly, I know ac-jump-buffer could do that, but its buffer list is too simple, no extra information such as mode, size column in buffer-menu. If you solve this problem, that would be appreciated. @zimbu668 – CodyChan Dec 30 '13 at 16:18
16

Just customize the variable same-window-regexps. display-buffer will display any buffer whose name matches a regexp there in the currently-selected window.

(You will want to add "[*]Buffer List".)

jrockway
  • 42,082
  • 9
  • 61
  • 86
  • 2
    This is the best answer here, as it gets down to the real issue (modifying how display-buffer behaves), as opposed to providing workarounds. – xyzzyz Mar 01 '17 at 00:51
14

not exactly a solution, but ido-mode provides a different and powerful way to interact with buffers. C-x b will then show a list of all the open buffers, and the one you select will open in the current window.

7

Strangely, there isn't an answer here about ibuffer.

I would recommend this as a standard change for the majority of Emacs users:

(global-set-key (kbd "C-x C-b") 'ibuffer)

ibuffer is a very advanced replacement for the default buffer listing, and not only features the exact behaviour requested, but provides a wealth of other functionality.

I listed a few ibuffer filtering and grouping basics in Emacs: help me understand file/buffer management, but be sure to read the documentation for details.

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
5

Try to add

(ido-mode 1)

to your .emacs, and enjoy the result :)

Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
3

If you like the original buffer list (as opposed to the 'buffer-menu solution proposed by others), you can use this:

(global-set-key (kbd "C-x C-b") 'my-list-buffers)
(defun my-list-buffers (&optional files-only)
  "Display a list of names of existing buffers.
The list is displayed in a buffer named `*Buffer List*'.
Note that buffers with names starting with spaces are omitted.
Non-null optional arg FILES-ONLY means mention only file buffers.

For more information, see the function `buffer-menu'."
  (interactive "P")
  (switch-to-buffer (list-buffers-noselect files-only)))

Which is the same function as before, only in the current window.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • I am using a variant now with switch-to-buffer-other-window and special behaviour if I am already in Buffer list. Thanks. – mkiever Sep 03 '15 at 15:56
2

I highly recommend bs.el from http://www.geekware.de/software/emacs/ Install it and:

(require 'bs)
(add-hook 'bs-mode-hook 'turn-on-font-lock)
(global-set-key "\C-x\C-b" 'bs-show)

It manages buffers and window configuration in the right way, so everything requires minimum number of keystrokes.

Gleb
  • 61
  • 2
1

Not sure where I got this but:

;;; Faster buffer switching
(global-set-key [(C tab)] 'buffer-menu) 

This makes Ctrl-Tab display all buffers in the current window. You can then navigate to a buffer and hit Enter to visit it.

Tim Stewart
  • 5,350
  • 2
  • 30
  • 45
0

Another not-what-you-asked-for solution: don't select the desired buffer with the mouse, rather finish typing its name (use tab-completion to reduce keystrokes and increase accuracy), then hit return. The buffer list will disappear, and the new file will be open in the previously active window.

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
  • Thanks - but I mostly work in the terminal so no mouse there... but sometimes I get confused whether some buffers begin with * or not, but you're right, tab completions will even help me out there. – hatmatrix Aug 05 '09 at 14:23
  • This does not remove the buffer list window for me ? – sandos May 06 '10 at 08:32