There’s a moment in every Emacs user’s journey when the key bindings stop feeling like alien hieroglyphics and start feeling like music. Your fingers develop muscle memory, and suddenly you’re navigating text at the speed of thought.
This chapter is about reaching that moment faster, and maybe having fewer hand cramps along the way.
Emacs was designed when keyboards looked different. The keyboard had the Control key where Caps Lock is now. This is important because it explains why Emacs seems determined to give you repetitive strain injury.
First thing you should do: Swap Caps Lock and Control. Seriously. Do it now.
setxkbmap -option ctrl:swapcaps to your .bashrc🚸 IDE Refugee Note: “But I use Caps Lock!” No, you don’t. Nobody does. And if you actually do, you can still access it—it’s just moved to where Control was. This one change will save your pinky finger from years of torture.
Yes, arrow keys work. But they’re so far away! Learn these and your hands never leave home row:
C-p (previous line)
↑
C-b ← C-f → (back/forward)
↓
C-n (next line)
Think of it as: back, forward, next, previous.
🤔 Why Though? These keys were chosen because they’re on the home row (well, close to it). Once you learn them, you can navigate without moving your hands. It’s like touch typing, but for navigation.
Characters are small. Words are better. Paragraphs are best:
M-f - Forward one wordM-b - Back one wordM-a - Beginning of sentenceM-e - End of sentenceM-{ - Beginning of paragraphM-} - End of paragraphNotice the pattern? Control for small movements, Meta for bigger movements.
C-a - Beginning of line (a for “start of alphabet”)C-e - End of line (e for “end”)These become so natural you’ll try to use them everywhere else and get frustrated when they don’t work.
M-< - Beginning of bufferM-> - End of bufferC-v - Page downM-v - Page up (Meta reverses things)C-l - Center screen on cursor (hit it multiple times!)🎯 Pro Tip: C-l cycles through center → top → bottom. It’s incredibly useful for positioning code exactly where you want it on screen.
Forget about carefully navigating to where you want to go. Just search for it:
C-s - Search forward (incremental search)C-r - Search backwardC-s C-s - Repeat last searchM-s w - Word search (spaces match any whitespace)While searching:
C-s again - Next matchC-r - Previous matchC-g - Cancel search, return to startEnter - Exit search, stay at match🚸 IDE Refugee Note: This isn’t like Ctrl+F in other editors. It’s incremental—it searches as you type. And when you’re done, just start typing to edit. No need to “close” the search.
Remember: Kill = Cut, Yank = Paste. Here’s the full dance:
C-k - Kill from cursor to end of lineC-w - Kill region (cut)M-w - Copy region (finally, a copy that’s not kill!)C-y - Yank (paste)M-y - Cycle through kill ringBut here’s where it gets beautiful:
M-d - Kill word forwardM-DEL - Kill word backwardC-x DEL - Kill to beginning of sentenceM-k - Kill to end of sentenceEverything you kill goes on the kill ring. It’s like having clipboard history built into your muscle memory.
C-/ or C-_ or C-x u - UndoBut here’s the advanced move: undo-tree (install it in Chapter 5). It turns your linear undo into a branching tree of possibilities. You can literally see alternate timelines of your document.
This isn’t built-in, but it’s so useful we’ll cheat and mention it here:
C-S-c C-S-c - Multiple cursors on each line in regionC-> - Mark next like thisC-< - Mark previous like this(We’ll install this package in Chapter 5, but I wanted you to know it exists.)
Registers are like variables for your editor. Store text, positions, or window configurations:
C-x r SPC a - Store position in register ‘a’C-x r j a - Jump to position in register ‘a’C-x r s a - Store region in register ‘a’C-x r i a - Insert contents of register ‘a’🎯 Pro Tip: Use registers for boilerplate text. Store your commonly-used code snippets and insert them instantly.
Remember, windows are the panes within your Emacs frame:
C-x o - Other window (cycles through)C-x 0 - Delete this windowC-x 1 - Delete other windows (maximize current)C-x 2 - Split horizontallyC-x 3 - Split verticallyC-x + - Balance windows (make them equal size)Advanced window-fu:
C-x 4 f - Find file in other windowC-x 4 b - Switch buffer in other windowC-x 4 0 - Kill buffer and windowEmacs uses prefix keys to group related commands:
C-x - Commands about files, buffers, windowsC-c - Mode-specific commandsC-h - Help commandsM-s - Search commandsC-x r - Register and rectangle commandsThis is why Emacs can have thousands of commands without running out of keys.
This will blow your mind. You can select and edit rectangular regions:
C-SPCC-x r k - Kill rectangleC-x r y - Yank rectangleC-x r t - Replace rectangle with textC-x r N - Number lines in rectangle🎮 Try This:
C-x r N to number themIf you’re coming from Vim, there’s Evil mode. It’s Vim emulation so good that Vim users switch to Emacs just to use it. We’ll cover this in the appendix, but know it exists.
This deserves its own chapter (and it’ll get one), but here’s a taste:
F3 or C-x ( - Start recording macroF4 or C-x ) - Stop recordingF4 or C-x e - Execute macroC-u 100 C-x e - Execute macro 100 timesExample: Add semicolons to the end of 100 lines:
F3 - Start recordingC-e ; - Go to end of line, add semicolonC-n C-a - Next line, beginningF4 - Stop recordingC-u 99 F4 - Do it 99 more timesThere are packages that completely reimagine Emacs keybindings:
g then commands without modifiers (g x s = C-x C-s)We’ll explore these in the packages chapter, but they show how flexible Emacs really is.
Here’s how to create your own keybindings:
;; Simple binding
(global-set-key (kbd "C-c t") 'toggle-truncate-lines)
;; Unbind something annoying
(global-unset-key (kbd "C-z")) ; Suspend frame
;; Bind function key
(global-set-key (kbd "<f5>") 'revert-buffer)
;; Create a prefix key
(define-prefix-command 'my-prefix-map)
(global-set-key (kbd "C-c m") 'my-prefix-map)
(define-key my-prefix-map (kbd "t") 'toggle-truncate-lines)
🚸 IDE Refugee Note: Yes, you can make Emacs use CUA keys (Ctrl+C for copy, etc.). Add (cua-mode t) to your config. But try the Emacs way first—it’s actually more powerful once you get used to it.
Don’t try to learn everything at once. Here’s a progression:
Week 1: Basic movement
C-f, C-b, C-n, C-pC-a, C-eM-f, M-bWeek 2: Killing and yanking
C-k, C-w, M-w, C-yM-d, M-DELWeek 3: Search and replace
C-s, C-rM-% (query replace)Week 4: Windows and buffers
C-x 2, C-x 3, C-x oC-x b, C-x C-bMonth 2: Advanced movement
🎮 Daily Drills:
(global-unset-key (kbd "<left>"))
(global-unset-key (kbd "<right>"))
(global-unset-key (kbd "<up>"))
(global-unset-key (kbd "<down>"))
Real talk: Emacs can hurt your hands if you’re not careful.
Prevention:
Alternative configurations:
Print this out and stick it on your monitor:
MOVEMENT EDITING SEARCH
C-f → C-k kill line C-s forward
C-b ← C-w kill region C-r backward
C-n ↓ M-w copy region C-M-s regexp
C-p ↑ C-y yank M-% replace
M-f word → M-y yank pop
M-b word ← C-/ undo FILES
C-a line start C-x C-f find
C-e line end WINDOWS C-x C-s save
M-< buffer start C-x 2 split horiz C-x C-w save as
M-> buffer end C-x 3 split vert
C-x o other HELP
C-x 1 only C-h k key
C-x 0 close C-h f function
Now that your fingers are learning to dance, Chapter 4 will show you how to make Emacs truly yours through configuration. We’ll start with simple tweaks and work our way up to a configuration that other Emacs users will envy.
But remember: keybindings are like vocabulary. The more you know, the more eloquently you can express your intentions to Emacs. And once you’re fluent, you’ll wonder how you ever lived without them.
“The keyboard is my piano, Emacs is my music, and text is my symphony.” —An Emacs user who learned all the keybindings
Master these keys, and you’ll edit text faster than you can think about editing text.