Categories
coding Emacs Lisp

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)
)))
Categories
coding Emacs Lisp

Emacs other-window backwards

I am currently writing a lot of text in Emacs, and I need to work on multiple files in parallel. So I use the split window functionality a lot. With C-x o you can switch to the next split window. However, it would be nice to go backward as well. The solution is simple, and is given on Stackoverflow and some other blogs:

(defun prev-window ()

(interactive)
(other-window -1))
(global-set-key (kbd "C-x p") 'prev-window)

Just put this in you init.el, and you can cycle backwards using C-x p.