33

I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
sjac
  • 2,811
  • 5
  • 23
  • 20
  • Does http://stackoverflow.com/questions/6813734/buffer-switching-in-emacs/6814873#6814873 cover this? – Michael Markert Sep 12 '11 at 21:36
  • 1
    I almost never use switch-to-buffer ^xb. // I often use buffer-menu (which I have bound to ^bm - I have my own, highly non-standard, keybindings). // I also have commands that switch to particular types of buffers, e.g. ^ss to switch to shell buffers, using a completing read on the foo part of a buffer name like *shell*. – Krazy Glew Sep 26 '13 at 04:56

8 Answers8

24

UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.

All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):

(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
               "*Messages*" "Async Shell Command"))

By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.

The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.

iswitchb-mode (Emacs < 24.4)

iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.

After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.

You can turn it on by default with this in your .emacs:

(iswitchb-mode 1)

You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:

(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
               "*Messages*" "Async Shell Command"))
Tyler
  • 9,872
  • 2
  • 33
  • 57
18

You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.

Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.

Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.

phimuemue
  • 34,669
  • 9
  • 84
  • 115
8

M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.

Also, take a look at smex.

Ross Patterson
  • 5,702
  • 20
  • 38
  • Thanks, this helped. I got a bit lost in Ido's doc about adding files from a file system tree to the completion list. Do you have same hints about how to set that up? – danza Mar 29 '16 at 09:20
  • 1
    @danza Not sure what you mean. With the options above, completion lists for finding files via `C-x C-f` are populated automatically. – Ross Patterson Mar 30 '16 at 15:25
  • My question did not make sense because i misunderstood the features provided by Ido. I thought that Ido would provide a way to find files at arbitrary depths. Eventually i settled on `helm-projectile`. Anyway, your answer allowed me to set up Ido really fast – danza Mar 30 '16 at 17:50
5
  1. ido-mode provides an efficient way to switch buffers.
  2. ibuffer is best for managing all opened buffers.
  3. anything is good for selecting an interested thing from different sources. (for eg: a single key can be used to switch to another buffer or to open recently closed file or to open a file residing in the same directory or ... anything you want ... )
kindahero
  • 5,817
  • 3
  • 25
  • 32
2

I have mapped the "§"-key to 'buffer-list and I find it to be very efficient.

KristianR
  • 420
  • 2
  • 6
  • I do something similar on a Microsoft keyboard, binding the 'menu' key (between the right-hand Alt & Ctrl) to `ibuffer`, which I find tremendously convenient. – phils Apr 26 '12 at 23:06
2

If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:

My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.

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

I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .

Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html

falsum
  • 349
  • 1
  • 7
0
  • My favourite function for this is helm-mini which is part of helm.

As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.

  • Something that I realized by accident and that can be useful:

mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.

prosoitos
  • 6,679
  • 5
  • 27
  • 41