Emacs Keyboard Shortcuts: Essential Keys and Commands
Emacs keyboard shortcuts are key sequences that run commands for moving around, editing text, saving files, and managing buffers. The basic notation is straightforward: C-x means hold Ctrl and press X, while M-x means hold Meta—usually Alt—or press Escape and then X; knowing these conventions makes the shortcuts easier to read and learn.
How Emacs Shortcut Notation Works
Emacs describes a key combination by naming the modifier, a hyphen, and the key. The two modifiers encountered most often are:
C-: hold the Control key while pressing the following key. For example,C-fmeans Ctrl+F.M-: hold the Meta key while pressing the following key. On many keyboards, Meta is mapped to Alt. If that does not work, press and release Escape, then press the next key;M-xcan therefore be entered as Escape followed by X.
A shortcut such as C-x C-s is a sequence: press Ctrl+X, release the keys, then press Ctrl+S. It is not one simultaneous four-key chord. Uppercase letters in conventional notation generally indicate the letter key, not that Shift is required: C-x is normally Ctrl+X.
Emacs is highly configurable, so a key may behave differently in a particular mode, configuration, terminal, or operating system. When in doubt, the built-in help system can show which command a key invokes.
Essential Shortcuts for Editing and Files
These common keys are a practical starting set. In Emacs, a command is an action, and a key binding is the shortcut that invokes it.
C-fandC-b: move forward or backward one character.C-nandC-p: move to the next or previous line.M-fandM-b: move forward or backward by a word.C-aandC-e: move to the beginning or end of the line.M-<andM->: move to the beginning or end of the buffer. These often require Meta+Shift with the comma or period key.C-d: delete the character at the cursor;Backspacedeletes the character before it.M-dandM-Backspace: delete forward or backward by a word.C-k: kill (cut) from the cursor to the end of the line. Emacs calls much of its cut-and-paste behavior “killing” and “yanking.”C-y: yank, or paste, the most recently killed text.C-/: undo in the standard Emacs setup. Depending on the keyboard and configuration,C-_orC-x umay also be available.C-x C-s: save the current file.C-x C-f: find or open a file. The command prompts for a file name and can also create a new file when you save it.C-x C-w: write the current buffer to a file, commonly used for saving it under another name.
“Kill” is not always the same as deleting text irreversibly: killed text is generally available to paste with C-y. Emacs maintains a kill ring, so M-y after a yank can cycle through earlier killed text in many standard configurations.
Windows, Buffers, and Search
Emacs uses “buffer” for the editable text area associated with a file or other content. A buffer is not necessarily the same thing as a visible window: several buffers can exist while only some are displayed.
C-x b: switch buffers; Emacs prompts for a buffer name.C-x C-b: display a buffer list.C-x 2: split the current window horizontally, creating a window above or below it.C-x 3: split the current window vertically, creating a side-by-side view.C-x o: move to another window.C-x 0: close the current window without necessarily closing its buffer.C-s: search forward incrementally; type to refine the search and pressC-sagain to find the next match.C-r: search backward incrementally.C-g: cancel or quit many active prompts and commands.
Splitting a window does not split a file into separate copies. It creates another view, which can be useful for comparing distant parts of the same buffer. If a search is still active, C-g is often the quickest way to stop it and return to ordinary editing.
Using M-x and Getting Help
Many Emacs commands can be run by name, even if you do not know their keyboard shortcut. Press M-x, type a command name, and press Enter. For example, M-x replace-string runs a text-replacement command; available commands depend on the Emacs version, loaded packages, and current mode.
Several help commands are especially useful:
C-h k, then a key sequence: explain the command currently bound to those keys.C-h f: describe a command by name.C-h v: describe a variable by name.C-h ?: open the help options available in the current setup.
For example, press C-h k and then C-a to ask Emacs what C-a does. This is more reliable than assuming a shortcut has its default meaning: major modes and personal configuration can change key bindings.
Learning Shortcuts Without Memorizing Everything
Start with movement, saving, opening files, searching, and canceling commands. Use a small set repeatedly before adding more. A simple session might involve opening a file with C-x C-f, moving with C-n and C-p, searching with C-s, and saving with C-x C-s.
When a key sequence is unfamiliar, consult help instead of guessing. The command M-x is also a useful fallback: if you know a command’s name but not its binding, you can often run it directly. Some commands have no default shortcut, and users can define their own bindings, so not every command name has a corresponding key sequence.
Emacs shortcuts can feel unusual because many use Ctrl and Meta rather than the single-key menus common in some editors. Their benefit is that commands can be composed into sequences, and the same command can often be reached by name or rebound to a preferred key. You do not need to learn the entire system to use Emacs productively.
Common Problems and Platform Differences
If M-x does not work, try pressing and releasing Escape, then X. Some desktop environments or terminal programs reserve Alt combinations, and keyboard layouts can affect keys such as angle brackets. In a terminal, the terminal emulator may interpret a key before Emacs receives it.
If a familiar shortcut performs an unexpected action, check the active major mode and use C-h k to inspect the binding. Emacs can also be configured to use different modifier keys. The exact menus and key behavior may therefore vary; a shortcut list is a guide to common defaults, not a promise that every installation is identical.
When Emacs appears to be waiting for more keys, it may be partway through a multi-key sequence such as C-x C-s. Press the next key in the sequence or use C-g to cancel. If a command is prompting for input, read the message in the minibuffer—the small prompt area usually shown at the bottom of the frame.
Frequently Asked Questions
What does C-x mean in Emacs?C-x means hold Ctrl and press X. It is also the beginning of many multi-key commands, so Emacs may wait for another key afterward.
What does M-x mean?M-x means Meta+X, usually Alt+X. You can also press and release Escape, then press X, and use it to run a command by name.
How do I save a file in Emacs?
Use C-x C-s to save the current file. If the buffer has not yet been associated with a file, use C-x C-f to enter a file name, then save.
How do I undo in Emacs?
In the standard setup, press C-/. If that key is inconvenient or unavailable, try C-_ or C-x u; bindings can vary by configuration.
How do I cancel a command in Emacs?
Press C-g to cancel many prompts, searches, and unfinished commands. It is a general-purpose way to get back to normal editing when you are unsure what Emacs is waiting for.
Can I change Emacs keyboard shortcuts?
Yes. Emacs is configurable, and users can bind commands to different keys. Because customization changes what a shortcut does, use C-h k to check the active binding in your current setup.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.