↓ Skip to main content
  1. Posts/

2- User Input & Text Navigation (Emacs Survival Guide)

·9 mins· loading · loading ·
ebeem
Author
ebeem
FOSS Enthusiast & Indie Game Developer

Introduction

With the terminology covered and your configuration ready from Part 1, it's time now to build your muscle memory. Navigating Emacs entirely by keyboard has no real shortcuts; it just requires patience, consistency, and a lot of practice. I can't promise you that you will memorize all of the keybindings in this guide, but I can assure you that you will be able to know the commands you need, how to invoke them, and how to recall their keybindings in case you forget them.

Once your muscle memory is built, editing in Emacs will feel like playing an instrument. You will never be using your mouse or arrow keys, and you will be pressing keys without even thinking about it.

Note: I found it extremely rewarding to invest in an ergonomic split keyboard. Also, if you're not typing properly on keyboard using touch typing, you may consider practicing it more as making typing mistakes in Emacs could be very inefficient.

The Input Hierarchy: Characters, Chords, and Sequences

Whenever you press a key on your keyboard, Emacs translates that key to an Elisp function and invokes it. There are three different types of Emacs keys that you need to be aware of:

Normal Characters

Standard alphanumeric keys (a–z, numbers, punctuation). These will most of the time be inserted directly into the focused buffer. Only in some special major modes (like Dired which will be explained later), the standard keys may actually trigger commands instead of inserting characters.

Key Chords

A key chord is when you press a normal character while holding down one or more modifier keys. The below table shows the modifier key symbol in addition to its keyboard key and Emacs. It's very similar to modern keyboard keys except for Meta, which refers to Alt (typical keyboards), or Option (Mac keyboards).

SymbolKeyboard KeyEmacs Name
CCtrlControl
MAlt or OptionMeta
SShiftShift

These symbols are combined with dashes to form key chords. The table below shows some key chords and how they are described in modern keyboard:

Emacs SymbolKeyboard Key
C-fControl+f
M-fAlt+f
C-M-nControl+alt+n
C-S-c / C-CControl+c

Key Sequences

A Key Sequence is a combination of key chords or normal characters pressed in order. We call the first key in this sequence prefix key, the keys or chords that follow it are separated by space. The table below shows examples of key sequences and how they are represented in modern keyboards.

Emacs SymbolKeyboard KeyPrefix Key
C-x C-fControl+x followed by Control+fC-x
C-x p pControl+x followed by p then pC-x
C-h kControl+h followed by kC-h

Essential Commands

Before learning how to move around, it's important to know first how to invoke a command by name, and how to cancel current command.

The Command Palette: M-x

I strongly recommend that you fire up Emacs and press M-x at this point. This guide will only be useful if you practice what you learn. You should see something like the screenshot below. If so, congrats! You're looking at the minibuffer.

From here, you can find a command using fuzzy searching, if you start typing space separated keywords (like prev line), the list will filter down to show you the command you're looking for. Next to each command, the minibuffer displays its keybinding and a brief description as well. This is the best way to recall a keybinding when you forget it. If you know that a command exists and remember part of its name, you can find it via M-x (execute-extended-command).

imgs/meta-x.jpeg

The Panic Button: C-g

C-g (keyboard-quit) is the universal escape keybinding. It aborts incomplete key sequences and active prompts. Try out pressing C-g (keyboard-quit) after pressing M-x (execute-extended-command), you should notice that the minibuffer will be closed.

Note: Throughout this guide, I use the format key (command-name) to show both the keybinding and its associated Emacs command. For example, C-g (keyboard-quit) means pressing C-g executes the keyboard-quit command.

You now know the two essential commands I want you to remember along with their keybindings. I won't ask you for now to remember any more keybindings or commands, I just want you to know that they exist and notice their command name pattern.

KeybindingFunction NameAction
M-xexecute-extended-commandInvokes any Emacs command by name
C-gkeyboard-quitUniversal panic button, cancels active prompts and operations

Font Scaling

If text looks smaller or larger than what you expect on your screen, these commands help you scale it up or down.

KeybindingFunction NameAction
C-x C-+text-scale-increaseIncreases buffer font size
C-x C--text-scale-decreaseDecreases buffer font size
C-x C-=text-scale-adjustResets buffer font size to default

Note: As mentioned earlier, there's no need to memorize keybindings. Notice the pattern in the function/command names of font scaling, they all begin with text-scale. You can run them directly by name via M-x. When you type text scale in your M-x, you will see these commands along with their keybindings to refresh your memory. Over time, muscle memory will take over and you won't need M-x as often.

Text Navigation

There is a mnemonic logic behind Emacs navigation keys, this might make them easier to recall early on. Once you build that muscle memory, you won't even think about the letters and naming anymore. If these mnemonics don't make sense to you, feel free to skip them:

  • f for Forward
  • b for Backward
  • n for Next line
  • p for Previous line
  • a for Ahead (start of line)
  • e for End of line

Short-Range Navigation

KeybindingFunctionWhat It Does
C-fforward-charGo to next character
C-bbackward-charGo to previous character
C-nnext-lineGo to the next line
C-pprevious-lineGo to the previous line
C-amove-beginning-of-lineGo to the beginning of the line
C-emove-end-of-lineGo to the end of the line
M-mback-to-indentationGo to the first non-whitespace character on the line
M-fforward-wordGo to next word
M-bbackward-wordGo to previous word

Long-Range Navigation

KeybindingFunctionWhat It Does
M-abackward-sentenceGo to the beginning of the sentence
M-eforward-sentenceGo to the end of the sentence
M-{backward-paragraphGo to the previous paragraph
M-}forward-paragraphGo to the next paragraph
M-<beginning-of-bufferGo to the beginning of the buffer
M->end-of-bufferGo to the end of the buffer
M-g ggoto-lineGo to the entered line number
M-g cgoto-charGo to a specific character offset

Universal Argument (C-u)

You may want to execute a command C-n (next-line) 10 times, which will take go to 10 line below. In such cases, it will be inefficient to press the chord 10 times. You can instead use C-u (universal-argument) to repeat the execution of a command. Try pressing C-u 10 C-n, this means you want to repeat the command C-n (next-line) 10 times, you can replace 10 with any number and C-n with any other command.

Deletion, Editing & The Kill Ring

A new concept and term to learn before proceeding is Kill Ring: a clipboard with history that stores every piece of text you cut or copy. Emacs was created long before modern conventions like cut, copy, paste, and clipboard were standardized, it invented its own concepts and terminology to describe them and they are in fact more powerful than typical copy and paste commands found in modern applications.

Deletion vs. Killing

Emacs has two concepts in deletion of text:

  • Deletion: Discards text without saving it (Delete).
  • Killing: Discards text and saves it into the Kill Ring (Cut).

Whenever you see a command that says kill, then it will cut the text and store it into the kill ring. If the command says delete, then it will delete the text without storing it anywhere.

KeybindingFunctionBehavior
DEL / BACKSPACEdelete-backward-charDeletes previous character (not saved to kill ring)
C-ddelete-charDeletes character under cursor (next character)
M-DELbackward-kill-wordCuts characters until previous word into kill ring
M-dkill-wordCuts characters until next word
C-kkill-lineCuts characters until the end of line (hit again to kill the newline)
C-S-BACKSPACEkill-whole-lineCuts current line (including newline)
M-kkill-sentenceCuts forward to end of sentence
M-z <char>zap-to-charCuts all characters until the specified character

Yanking and Cycling the Kill Ring

In Emacs terminology, pasting is called Yanking. Another key concept to learn before proceeding is Region: the currently highlighted or selected text in a buffer. You can click and drag in Emacs with your mouse to select text like you do in any other application such as your web browser. However, the Emacs way is to press C-SPC (set-mark-command). This sets a marker at your cursor, moving anywhere with Emacs navigation keys and commands will then expand the highlighted region. We’ll discuss other methodologies to select text in later articles.

In Emacs, the cursor position is called the Point. When you press C-SPC (set-mark-command), you store current Point position into the Mark. The area between your Point and Mark is the active Region.

Note: Don't forget your panic button, C-g (keyboard-quit)! It can be used to cancel the selection/active region.

KeybindingFunctionBehavior
C-SPCset-mark-commandActivates marker (selection), C-g (keyboard-quit) to cancel
C-x C-xexchange-point-and-markSwaps point and mark, helpful to expand selection from the other direction
C-wkill-regionCuts the active region
M-wkill-ring-saveCopies the active region
C-yyankPastes most recent entry from the kill ring
M-yyank-popPastes a selected entry from the kill ring

Formatting & Indentation

KeybindingFunctionAction
C-oopen-lineInserts a newline after the point and keeps the cursor position
C-M-osplit-lineSplits line at point
M-SPCcycle-spacingCycles whitespace around point (single space, no space, original)
M-^delete-indentationJoins current line with the line above

Case Transformations & History Recovery

Text Case Manipulation

KeybindingFunctionAction
M-uupcase-wordConverts remainder of word at point to UPPERCASE
M-ldowncase-wordConverts remainder of word at point to lowercase
M-ccapitalize-wordCapitalizes the leading letter of the word at point
C-x C-uupcase-regionConverts active region to UPPERCASE
C-x C-ldowncase-regionConverts active region to lowercase

Undo, Redo, and Recovery

Emacs offers powerful ways to navigate and revert edit history, for the sake of simplicity, your setup is configured to follow conventional undo and redo behavior.

KeybindingFunctionAction
C-_ or C-/undoUndoes previous changes
C-M-_undo-redoRedoes undone changes
revert-bufferReloads the file fresh from disk

Note: Leaving the keybinding empty for revert-buffer isn't a typo! Emacs comes with thousands of built-in commands and that number grows as you install packages and write your own functions. Only a fraction of commands are bound to keys. Later, you'll learn how to assign custom keybindings to your most frequently used commands. In the meantime, any unbound command can be run anytime via M-x (execute-extended-command).

What's Next?

In Part 3: Search and Replace, Files, and Projects, we will explore Emacs's Incremental Search (isearch), query replacements, Occur mode, and how the mark and region system work in detail.