GNU Emacs is a text editor with no separate mode for typing: you open a file and type, and every command runs from a key chord or by its name. That second part is what lets Emacs grow into a notes app or a Git client without you ever leaving the editor.
You just type
Vim opens in a mode where keys are commands, so you press i before you can write anything (the Vim page walks through that). Emacs has no such split. Every ordinary key inserts its character at the cursor from the moment the file opens. Emacs does use the word 'mode', but for something else: a major mode such as Org mode sets how one kind of file behaves, and you never switch out of it to type.
Commands therefore need keys that can't be mistaken for text. Emacs uses modifier keys, written in a short notation you'll see everywhere:
C-xmeans hold Ctrl and press x.M-xmeans hold Meta and press x. On a modern keyboard Meta is the Alt key. If Alt doesn't reach Emacs, as on some terminals, press and release Esc, then the key.C-x C-sis two chords in a row: Ctrl+x, then Ctrl+s.
Text you edit lives in a buffer. C-x C-f (find-file) reads a file into a buffer, and nothing reaches the disk until you save. Give it a name that doesn't exist yet and Emacs creates the file on the first save.
Key chords and prefix keys
C-x on its own does nothing. It's a prefix key: Emacs waits for the next key to know which command you mean, and if you pause for a second it shows C-x- at the bottom of the screen. Prefix keys give Emacs room for hundreds of bindings: C-x C-f opens a file, C-x C-s saves it and C-x C-c quits.
When you save, the bottom line, called the echo area, confirms it with 'Wrote' and the full path. The mode line just above it changes too: it shows ** near the left edge while the buffer has unsaved changes, and -- once it's saved.
The other chord to learn on day one is C-g. It cancels whatever you started: a half-typed chord, a prompt, or a command that's taking too long. Emacs answers with 'Quit'. Here C-x C-s saves the notes, then C-x C-f opens a prompt and C-g throws it away:
Undo is C-/ (also C-x u). Press it again to keep stepping back through earlier changes.
M-x runs any command by name
Every command in Emacs has a name, such as save-buffer or forward-word, and key bindings are shortcuts to some of them. The manual says most commands have no binding at all, so the only way to run them is by name, with M-x.
Press M-x and a prompt opens at the bottom. Type part of a name and press Tab to complete it, or press Tab on its own to list every command. A stock install has thousands, and each package adds more. Press Enter to run the command. If it also has a key binding, Emacs tells you afterwards, so M-x doubles as a way to learn shortcuts. C-g backs out without running anything.
Two help keys come from the same idea. C-h k followed by a key tells you which command that key runs, and C-h t opens the built-in tutorial. Help read straight from the commands is part of what the manual means when it calls Emacs 'self-documenting'.
An editor you extend
Most of Emacs is written in Emacs Lisp, the same language its packages use, so a package can add commands, key bindings and whole new kinds of buffer the same way the built-in parts do. With enough installed, Emacs sits somewhere between a code editor and an IDE. That's where the old joke comes from: Emacs is a great operating system that only lacks a decent text editor.
Some of the best-known extensions ship with Emacs. Others come from the package archives: run M-x package-install, type the package name and press Enter. Since Emacs 28, both archives run by the Emacs developers, GNU ELPA and NonGNU ELPA, are on by default.
Org mode: notes and to-do lists in plain text
Org mode is part of Emacs and starts when you open a file ending in .org. An Org file is plain text with structure: a line starting with * is a heading, ** is a heading under it, and a heading that starts with TODO is a task.
Tab on a heading folds or unfolds it, and Shift+Tab cycles the whole file between the top headings, every heading, and everything. C-c C-t on a task moves it from TODO to DONE. Here a short shop list folds down to its headings, then the first task is ticked off:
Because it's plain text, an Org file opens in any editor and diffs cleanly in Git. Org also gathers TODOs from all your files into an agenda, and exports to HTML or PDF, so people run whole projects and journals in it.
Magit: Git from a status buffer
Magit isn't built in; install it from NonGNU ELPA. Its manual calls it a complete text-based user interface to Git. C-x g opens the status buffer, which lists unstaged changes, staged changes and recent commits, and almost everything in it can be acted on with a key or two.
Move to a change and press s to stage it. That works on a whole file or on a single hunk, which in plain Git takes an interactive session such as git add --interactive. Press c twice to start a commit, and Emacs opens a buffer for the message beside the diff you're committing. Write the message and press C-c C-c:
Behind the scenes Magit runs ordinary Git commands, so nothing it does is hidden from the command line. Some people who write code in another editor keep Emacs around just for Magit.
Games and a therapist
M-x tetris, M-x snake and M-x pong are built-in games. M-x doctor starts a psychotherapist modelled on the 1960s ELIZA program: type a sentence, press Enter twice, and it replies. They're toys, but they make the point of M-x: every feature is a command with a name.
Emacs pinky
Most chords lean on Ctrl, and on a standard keyboard Ctrl sits under the little finger. Press it hundreds of times a day and the strain gets a name among Emacs users: Emacs pinky.
The usual fix is to move the key. Many users make Caps Lock a second Ctrl in their operating system's keyboard settings, so the finger barely stretches. Others press Ctrl with the side of the palm, or use the Ctrl key on the opposite side from the letter. Some stop using chords for most editing altogether.
Evil mode: Vim's keys inside Emacs
That last group installs Evil, 'the extensible vi layer for Emacs'. It emulates Vim's main features and makes Emacs a modal editor, with the normal and insert modes you know from Vim. Install it from NonGNU ELPA, then run M-x evil-mode. The mode line shows <N> for normal state, and h, j, k, l and dd work as they do in Vim:
Evil calls modes 'states'. i switches to insert state (<I>), and C-z switches to Emacs state (<E>), where the Vim keys are off until you press C-z again. Org, Magit and every M-x command keep working throughout, so you get Vim keys for editing and Emacs for everything around them.
Saving and leaving
C-x C-c quits. The manual says it's two chords so you can't type it by accident. If any file has unsaved changes, Emacs asks about each one first: y saves it, n skips it. Skip one and Emacs asks once more before throwing the changes away.
A worked example
Say the shop keeps its to-do list in Org and its menu in Git, and sardines need adding to the menu. Start with emacs menu.txt in the terminal, then:
- Move to the end of the list and type 'sardines'. There's no mode to enter first.
C-x C-ssaves. The echo area shows 'Wrote' and the path, and the**disappears.C-x gopens Magit. Put the cursor onmenu.txtunder 'Unstaged changes' and presss.c copens the commit message. Type 'Add sardines' and pressC-c C-c.C-x C-f todo.orgopens the to-do list. PressC-c C-ton the task to mark it DONE, thenC-x C-s.C-x C-cquits without asking, because both files are saved.
Press a wrong chord at any point and C-g gets you back.
Common mistakes
- Pressing Esc to cancel. Esc starts a Meta chord, so Emacs waits for another key.
C-gis the cancel key, and it clears a stray Esc too. - Expecting Ctrl+C and Ctrl+V. Emacs copies with
M-w, cuts withC-wand pastes withC-y. For the usual shortcuts, turn onM-x cua-mode. - Leaving a prefix key hanging. After
C-x, the next thing you type is read as part of a command. PressC-gand start again.
Key takeaways
- Emacs has no insert mode: ordinary keys type, and commands use Ctrl and Meta (Alt) chords.
C-x C-ssaves,C-gcancels,C-/undoes andC-x C-cquits.M-xruns any command by name, including the many with no key binding.- Org mode, Magit and Evil turn Emacs into a notes app, a Git client and a Vim-style editor.
- Remap Caps Lock to Ctrl, or use Evil, if the chords start to hurt.