2012-05-14

Quickly toggle last two buffers in Emacs

I don't have much interesting stuff to post this month, so I'll just go with one little snippet for Emacs. Next months will be better, I promise!
In Emacs, you can switch buffers by hitting C-x b and typing a buffer name. If you just hit C-x b RET, Emacs will just go to the last buffer. This is an awful lot of keys for such a simple function. So quite a long time ago, I found this useful small function, but I forgot where. In my config I've bound it to F4. I use the function keys quite a bit for file and buffer operations, maybe because I am a big fan of the Midnight Commander...

(global-set-key [f4] (lambda () 
                      (interactive) 
                      (switch-to-buffer
                         (other-buffer 
                             (current-buffer) nil)
                      )))

No comments:

Post a Comment