8

I would like to emulate Alt-Tab as it works with individual windows on GTK, but with Ctrl-Tab within buffers in emacs.

So, for example, if I have ten buffers open in emacs, and I am working on two at the moment, say Buffer1 and Buffer2, and I am in Buffer1 currently, I would like Ctrl-Tab to take me to Buffer2, and on pressing Ctrl-Tab again, back to Buffer1.

In case I need to go to Buffer3, or Buffer4 etc, I keep Ctrl pressed while I press Tab.

Does this make sense? If so, please tell me how I can do this.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
xoxa
  • 81
  • 1
  • 2
  • 1
    You might want to look at [iswitch-b](http://www.emacswiki.org/emacs/IswitchBuffers) -- this is much more useful to me than cycling through all buffers as I normally have *many* buffers open. – jaybee Jul 25 '11 at 09:23
  • Check out [ido-mode](http://www.emacswiki.org/emacs/InteractivelyDoThings). "C-x b RET" flips back to your most recently opened buffer. Otherwise you can choose another buffer using fuzzy matching. It only becomes awesome after you've tried it. You will never switch to any other buffer switching mechanism, I promise! ;) Here is a [video](http://www.youtube.com/watch?v=lsgPNVIMkIE) of someone demonstrating its features. If you are using emacs 22 or greater, ido-mode is included. Type "M-x ido-mode RET" and then "C-x b" to try it out. – Ryan Kaskel Jul 25 '11 at 12:42
  • Alt-tabbing is very inefficient. I recommend [iswitchb](http://www.emacswiki.org/emacs/IswitchBuffers) instead. You can type any part of the buffer name to switch to it. It's much quicker and easier especially if you have quite a few buffers open. Give it a try. – Tom Jul 25 '11 at 20:12

5 Answers5

6

What are you using currently?

But I think

(global-set-key (kbd "C-<tab>") 'next-buffer)
(global-set-key (kbd "C-S-<tab>") 'previous-buffer)

should be doing what you describe.

As jaybee comments, it may be a whole less useful than in, say, Firefox. But I'd recommend ido-switch-buffer.

This may also be of interest: http://www.emacswiki.org/emacs/ControlTABbufferCycling

Michael Markert
  • 3,986
  • 2
  • 19
  • 19
  • `(kbd "C-TAB")` does not work for me (trying to use Ctrl+Tab results in " is undefined"). And evaluating `(kbd "C-tab")` raises "C- must prefix a single character, not tab". But this works: `(kbd "C-")`. – mzjn Jul 25 '11 at 13:19
  • You are right. There's something strange going on: `(kbd "TAB")` works as `(kbd "")` is translated to it, but that translation does not happen on `(kbd "TAB")`. – Michael Markert Jul 25 '11 at 13:41
  • That last `(kbd "TAB")` should be a `(kbd "C-TAB")` – Michael Markert Jul 25 '11 at 13:52
3

I think swbuff works well. See http://www.emacswiki.org/emacs/SwBuff.

From my init file:

(require 'swbuff)
(global-set-key [(control tab)] 'swbuff-switch-to-next-buffer)
mzjn
  • 48,958
  • 13
  • 128
  • 248
3

Switch between the two most recent buffers

(global-set-key [\C-tab]
        (lambda () (interactive)
          (switch-to-buffer (other-buffer))))
xevincent
  • 3,674
  • 18
  • 20
2

I'm quite happy with this setup:

(defun next-line-cycle ()
  "Go to next line. Go to first line if end is reached."
  (interactive)
  (revert-buffer)
  (if (= (line-number-at-pos) (count-lines (window-start) (window-end)))
      (backward-page)
    (forward-line)))
(defun ctrltab ()
  "List buffers and give it focus"
  (interactive)
  (if (string= "*Buffer List*" (buffer-name))
      (next-line-cycle)
    (progn (list-buffers)
       (switch-to-buffer "*Buffer List*")
       (delete-other-windows)
       (forward-line))))
(global-set-key [C-tab] 'ctrltab)

Usage pattern:

* hold ctrl, press <tab> once, keep holding ctrl
* press 'm' to view currently selected buffer
* press <tab>(possibly more times) to select next buffer

This works well when you don't want to enter the buffer name (e.g. ido-mode) to switch (maybe a cup of coffee in the right hand).

abo-abo
  • 20,038
  • 3
  • 50
  • 71
2

Sounds like you would like to try out iflipb:

(require 'iflipb)
(global-set-key (kbd "<C-tab>") 'iflipb-next-buffer)
(global-set-key (kbd "<C-S-iso-lefttab>") 'iflipb-previous-buffer)
Joel Rosdahl
  • 846
  • 9
  • 12