Chapter 3: Movement and Key Bindings
Your Fingers Will Learn to Dance
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.
The Home Row Philosophy
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.
- macOS: System Preferences → Keyboard → Modifier Keys
- Linux: Add
setxkbmap -option ctrl:swapcapsto your.bashrc - Windows: Use PowerToys or SharpKeys
🚸 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.
Basic Movement: Beyond the Arrow Keys
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.
Word and Paragraph Movement
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 paragraph
Notice the pattern? Control for small movements, Meta for bigger movements.
Line Movement: Your Most-Used Commands
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.
Screen Movement: When You Need to Jump
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.
The Mighty Search: Your Navigation Superpower
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-sagain - 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.
The Kill Ring Dance: Cut, Copy, and Paste Evolved
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 ring
But 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 sentence
Everything you kill goes on the kill ring. It’s like having clipboard history built into your muscle memory.
Undo/Redo: The Tree of Possibilities
C-/orC-_orC-x u- Undo- Undo your undos: Move cursor, then undo again
But 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.
Multiple Cursors: When One Isn’t Enough
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: Your Bookmark System
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.
Window Navigation: Dancing Through Panes
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 window
The Prefix Key Pattern
Emacs 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 commands
This is why Emacs can have thousands of commands without running out of keys.
Rectangle Editing: The Hidden Superpower
This will blow your mind. You can select and edit rectangular regions:
- Set mark at corner:
C-SPC - Move to opposite corner
C-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:
- Create a list of items
- Select a rectangle at the beginning of all lines
C-x r Nto number them- Watch minds blow (including your own)
The Modal Alternative: Evil Mode
If 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.
Keyboard Macros: Your Personal Robot
This deserves its own chapter (and it’ll get one), but here’s a taste:
F3orC-x (- Start recording macro- Do stuff
F4orC-x )- Stop recordingF4orC-x e- Execute macroC-u 100 C-x e- Execute macro 100 times
Example: 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 times
God Mode and Other Insanity
There are packages that completely reimagine Emacs keybindings:
- God Mode: Type
gthen commands without modifiers (g x s=C-x C-s) - Hydra: Create custom key sequence menus
- Which Key: Shows available keys after a prefix
- Key Chord: Trigger commands with two-key combos
We’ll explore these in the packages chapter, but they show how flexible Emacs really is.
Your Personal Keybinding Manifesto
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.
The Learning Curve Strategy
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-b
Week 2: Killing and yanking
C-k,C-w,M-w,C-yM-d,M-DEL
Week 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-b
Month 2: Advanced movement
- Registers
- Rectangles
- Macros
Exercises to Build Muscle Memory
🎮 Daily Drills:
- The No-Arrow Challenge: Disable arrow keys for a day
(global-unset-key (kbd "<left>")) (global-unset-key (kbd "<right>")) (global-unset-key (kbd "<up>")) (global-unset-key (kbd "<down>")) - The Speed Run:
- Open a file
- Navigate to 5 specific words using search
- Kill 3 lines, yank them elsewhere
- Time yourself, try to beat it
- The Rectangle Puzzle:
- Create a CSV file
- Use rectangles to rearrange columns
- Add line numbers to one column
- The Macro Marathon:
- Find a repetitive task
- Solve it with a macro
- Feel like a wizard
The Ergonomics Section
Real talk: Emacs can hurt your hands if you’re not careful.
Prevention:
- Swap Caps Lock and Control (seriously, do it)
- Use sticky keys if needed (tap Control instead of holding)
- Learn to use both Control keys
- Take breaks
- Consider foot pedals for modifiers (I’m not joking)
Alternative configurations:
- Spacemacs: Space bar as leader key
- Doom Emacs: Modern keybindings
- Ergoemacs: Ergonomic keybindings
The Keybinding Cheat Sheet
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
What’s Next?
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
Chapter 3 Summary
- Movement is modal: Character → Word → Line → Paragraph → Screen
- Search is faster than navigation
- Kill ring > clipboard
- Registers are bookmarks and variables
- Rectangles are mind-blowing
- Macros are your personal automation
- Customize everything—make Emacs fit your hands
Master these keys, and you’ll edit text faster than you can think about editing text.