Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I more easily switch between buffers in Emacs?

Tags:

emacs

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.

like image 237
sjac Avatar asked Sep 12 '11 21:09

sjac


People also ask

How do you change from one buffer to another?

For conveniently switching between a few buffers, use the commands C-x LEFT and C-x RIGHT . C-x LEFT ( previous-buffer ) selects the previous buffer (following the order of most recent selection in the current frame), while C-x RIGHT ( next-buffer ) moves through buffers in the reverse direction.

How do I navigate between buffers in Vim?

script, and place the following in your vimrc. Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.

Can you have more than one buffer in Emacs?

When Emacs has multiple windows, each window has a chosen buffer which is displayed there, but at any time only one of the windows is selected and its chosen buffer is the selected buffer. Each window's mode line displays the name of the buffer that the window is displaying (see section Multiple Windows).

Can you only have one buffer open in Emacs at a time?

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears.


2 Answers

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")) 
like image 97
Tyler Avatar answered Oct 14 '22 12:10

Tyler


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.

like image 21
phimuemue Avatar answered Oct 14 '22 12:10

phimuemue