Today I’m going to write about some lesser-known Emacs bindings, namely ones beginning with C-x 4
. (In general, C-x DIGIT
bindings are sometimes interesting; while everyone knows C-x 1
and C-x 2
, it might be a good idea to press C-x 3
, C-x 8 C-h
and a few other combinations.)
C-x 4
, however, is a treasure chest. Well, maybe not that much, but there are a few really useful things beginning with it. So, let’s get started.
First, C-x 4 C-f
(or C-x 4 f
– find-file-other-window
), which finds a file in another (newly created) window. Basically, it is a shorthand for C-x 2 C-x o C-x C-f
(maybe not exactly, but you get the idea). Quite useful if you happen to need to edit a file while seeing the previous one.
Next is C-x 4 C-o
(display-buffer
), which is (potentially) even more useful. It opens another window (again, like C-x 2
), but instead if showing the same buffer, shows another one, the name of which is read from the minibuffer. Note that the newly opened window does not get selected! Just in case you forgot, you can scroll the other window with C-M-v
and C-M-S-v
.
Another useful command is C-x 4 0
(kill-buffer-and-window
), which not only deletes the current window (like C-x 0
), but also kills its buffer. There is also C-x 4 b
(switch-to-buffer-other-window
), which does exactly what it says on the tin, C-x 4 d
(dired-other-window
– you can guess what it does), and one of the best of them all: C-x 4 c
. This last keychord is bound to the command clone-indirect-buffer-other-window
. It splits the current window, clones the current buffer and visits the clone in the newly opened window.
What is it useful for? Well, if you open the same buffer in two windows simultaneously, both windows share a few things; one of them is narrowing. I’m a heavy narrowing addict, and very often find myself editing (or viewing) a buffer narrowed to some fragment (be it a defun, a LaTeX section, or an Org-mode subtree). Sometimes, however, I need something from some other part of the file I’m editing, and C-x 2
is not enough then: if I widen the buffer in one window, it gets widened globally. What I can do then is: press C-x 4 c C-x n w
, do whatever I need, and C-x 4 0
.
Note: I hear that Drew Adams’ Wide-N library is another way to solve a similar problem. I will definitely try it at some point. Still, I think that C-x 4
bindings – and C-x 4 c
in particular – are worth knowing anyway! And don’t forget that you can press C-x 4 C-h
to see all of them.