Text Editing 201¶
[Intro to emacs, what it is, how it’s different to Vi]
Vi was first developed on computers where the keyboards looked like this:
Emacs was first developed on computers where the keyboards looked like this:
The important thing to note in the Symbolics keyboard above is the keys on the bottom row:
[ SPACE ]
Where Vi has modes for different editing tasks with composable commands, Emacs relies on key combinations or “chords”, particularly the
META keys, abbreviated
The convention for canonically specifying a keyboard combination in Emacs is based on those abbreviations using a connecting dash for keys pressed simultanously and a space for follow-up key “arguments”.
For example, the most important key combination in Emacs is this one:
C-h ? meaning, press and hold
Ctrl then press
h, release and press
?. This takes you to Emacs’ “help” options.
Modern keyboards lack a
META key, but Emacs has long recognized
For example, the second most important key combination in Emacs is
M-x, meaning press and hold
Alt and then press
This brings up what amounts to Emacs’ “command line” where you can enter any Emacs command to run.
It bears mentioning the “zeroth” most important key command:
C-g meaning press and hold
Ctrl and press
This tells Emacs to cancel whatever it’s doing.
It almost always works, although sometimes after a short wait.
C-g combines with every partial keyboard combination to cancel it.
What Emacs lacks in command composability, it makes up for in programmability.
Nearly every aspect of the editing experience is modifiable using Emacs’ native language, Emacs Lisp.
You can use
M-: to open another Emacs’ command-line, this one takes any Emacs Lisp expression and evaluates it.
You can also go to the “scratch” buffer, enter an Emacs lisp expression and press
C-x C-e to evaluate it.
You can read Emacs’ online manuals at
Going through the Emacs tutorial—
C-h t—is highly recommended.
To close Emacs
find-fileopen a file in a buffer to edit
kill-bufferclose a buffer
C-x C-f /sudo:localhost:/etc/hostsuse Tramp-mode to edit a privileged file (of course, you must be privileged)
switch-to-bufferswitch to another open buffer
M-x ibuffersee a list of open buffers, to navigate or run other commands on
Emacs autodetects the kind of file one is operating on and applies syntax highlighting as part of the “mode” used for that buffer.
Emacs comes with built-in modes for almost everything.
You can explicitly run any mode with
Emacs typically shows the cursor’s position in a buffer on the “mode-line” near the bottom of the screen.
You can configure it to show the position in a “row and column” format running
M-x line-number-mode (usually on by default) and
To see line numbers in buffer use
To highlight the current line use
split-window-belowsplits the window horizonally (especially useful for looking at two widely separated parts of the same buffer).
split-window-rightsplits the window vertically
other-windowswitches focus to other window
delete-windowcloses this window
delete-other-windowscloses the other window
C-x 4 f
find-file-other-windowopens file in other window
C-x 4 r
C-x 4 b