Emacs

Table of Contents

Customizations specific to aprl-emacs are shown here.

Basic commands

C here denotes the <control> key, and M denotes the meta key (either <alt> or <escape>).

task keybinding function
open/create file C-x C-f (find-file)
save C-x C-s (save-buffer)
save as C-x C-w (write-file)
escape/stop C-g (keyboard-quit)
undo C-x u (undo)
cut C-w (kill-region)
copy M-w (kill-ring-save)
paste C-y (yank)
read-only (toggle) C-x C-q (toggle-read-only)
exit C-x C-c (save-buffers-kill-terminal)
  • Arrow keys also often work for navigation.
  • <shift> + arrow keys also work for highlighting, but you can also highlight regions by pressing C-<space> before and after cursor movement.

Help:

task keybinding function
describe function C-h f (describe-function)
describe variable C-h v (describe-function)
display documentation of the function invoked by keystrokes C-h k (describe-key)
show a list of all defined keys, and their definitions C-h b (describe-bindings)

More on help.

Lists in buffer:

task keybinding function
list buffers C-x b (list-buffers)
list files in directory C-x d (dired)
  • (ibuffers) is more powerful than (list-buffers) so I have this rebound.

Navigation

Basic cursor movement:

unit of increment backward forward
character C-b (backward-char) C-f (forward-char)
word M-b (backward-word) M-f (forward-word)
sentence M-a (backward-sentence) M-e (forward-sentence)
line C-a (beginning-of-line) C-e (end-of-line)
line C-p (previous-line) C-n (next-line)
paragraph M-{ (backward-paragraph) M-} (next-paragraph)
page M-v (scroll-up) C-v (scroll-down)
buffer M-< (beginning-of-buffer) M-> (end-of-buffer)

Note that M-a and M-e in shell mode and minibuffer take you to the point after the shell prompt rather than the line.

  • Very powerful: to return to last point after navigation move, use C-x C-SPC to return to previous cursor position (pop-global-mark).
  • Prefix keystrokes with C-u n where n = number of times to repeat. For instance, to go up 10 lines rather than one: C-u 10 C-p.
  • M-r moves cursor to left margin on center line of page (move-to-window-line); useful after scrolling (M-v or C-v).

Mark:

unit keybinding function
word M-@ (mark-word)
sentence [] (mark-end-of-sentence)
paragraph M-h (mark-paragraph)
page C-x C-p (mark-page)
buffer C-x h (mark-whole-buffer)

Goto functions:

keybinding function
M-g c (goto-char)
M-g g (goto-line)

"Move to" functions:

keybinding function
M-r (move-to-window-line)

Another way to move around the buffer is through [[./more-editing.org::sec:search][incremental searching].

Reposition window relative to cursor:

keybinding function
C-l (recenter-top-bottom)
C-M-l (command-reposition-window)

Killing:

keybinding backward forward
character DEL (delete-backward-char) C-d (delete-char)
word M-DEL (backward-kill-word) M-d (kill-word)
line   C-k (kill-line)
sentence C-x DEL (backward-kill-sentence) M-k (kill-sentence)

There are additional functions, (backward-kill-paragraph) and (kill-paragraph), which can be accessed interactively, but are not bound to keybindings by default. As mentioned above, for C-u can be used in conjunction with many of these functions. E.g., to kill 5 lines, C-u 5 C-k. See also rectangle functions for killing and yanking (CUA-mode is good for this also).

Learn more ways to edit text.

Managing windows, frames, screens

(elscreen is a package installed separately.)

Management

function window frame elscreen
make/create C-x 2, C-x 3 C-x 5 2 C-z c
delete   C-x 5 0 C-z k
kill-buffer and delete window/screen C-x 4 0   C-z M-k
delete others C-x 4 1 C-x 5 1 C-z K
other C-x o C-x 5 o C-z p, C-z n
  • C-x o takes a prefix argument of COUNT, which is the number of windows to move forward/backward (-n to n).
  • I have mapped C-c o for switching among frames; C-u C-c o will move through frames in the opposite direction (akin to Command-` and Shift-Command-` or Alt-` and Shift-Alt-` allowed by the OS).

Common tasks

function current window -other-window -other-frame elscreen-
find-file C-x C-f C-x 4 C-f or C-x 4 f C-x 5 C-f or C-x 5 f C-z C-f or C-z f
find-file-read-only C-x C-r C-x 4 r C-x 5 r C-z C-r
dired C-x d C-x 4 d C-x 5 d C-z d
switch-to-buffer C-x b C-x 4 b C-x 5 b C-z b
clone   C-x 4 c C-x 5 c C-z C

See also Managing frames and windows.

See also


Generated by Org-mode 9.2 with Emacs 26