This is a non-exhaustive list of custom Emacs key bindings that I use on a regular basis.

Select next or previous window

Because C-x o and C-​- C-x o are too verbose.

(defun my-select-next-window ()
  (interactive)
  (other-window 1))

(defun my-select-previous-window ()
  (interactive)
  (other-window -1))

(bind-key* "M-o" #'my-select-next-window)
(bind-key* "M-O" #'my-select-previous-window)

Swap two adjacent windows

(require 'crux)

(bind-key "C-x 4 t" #'crux-transpose-windows)

Bury and unbury buffers

Sometimes you just want to get a buffer out of the way without killing it. Then sometimes you want to get it back.

(bind-key "C-c z" #'bury-buffer)
(bind-key "C-c Z" #'unbury-buffer)

Kill buffer without prompting

(bind-key "s-k" #'kill-current-buffer)

Switch to scratch buffer

This one pairs well with kill-current-buffer, as switching to a non-existent scratch buffer recreates it with default settings.

(defun my-switch-to-scratch-buffer ()
  (interactive)
  (switch-to-buffer "*scratch*"))

(bind-key "C-c s" #'my-switch-to-scratch-buffer)

DWIM case changing

The default Emacs bindings for downcase-word, upcase-word, and capitalize-word seem to me strictly less useful than their DWIM alternatives, which function on both words and regions.

(bind-key [remap downcase-word] #'downcase-dwim)
(bind-key [remap upcase-word] #'upcase-dwim)
(bind-key [remap capitalize-word] #'capitalize-dwim)

Zap up to char

Emacs binds M-z to zap-to-char​. The kills everything up to and including the next occurrence of whatever character you type.

As a reformed vi user, I missed the ability to stop just short of the character. Turns out Emacs has this, but doesn’t bind it.

(bind-key "M-Z" #'zap-up-to-char)

Jump directly to the source of a given command

These work just like describe-function and describe-key, except you get the source code instead of a Help buffer.

(bind-key "C-h M-f" #'find-function)
(bind-key "C-h M-k" #'find-function-on-key)

Reopen current file or directory as root

I use the crux package for this, but you can also use sudo-edit.

(require 'crux)

(bind-key "C-c S" #'crux-sudo-edit)

See also

✏ Edited