Contents
Contents
Introduction
Thank You . . . . . . . . . . . . . . . . . . . .
Intended Audience . . . . . . . . . . . . . . . .
What You’ll Learn . . . . . . . . . . . . . . . .
The Way of Emacs
Guiding Philosophy . . . . . . . . . . . . . . . .
LISP? . . . . . . . . . . . . . . . . . . . . .
Extensibility . . . . . . . . . . . . . . . . .
Important Conventions . . . . . . . . . . . . . .
The Buffer . . . . . . . . . . . . . . . . . .
The Window and the Frame . . . . . . . .
The Point and Mark . . . . . . . . . . . . .
Killing, Yanking and CUA . . . . . . . . .
.emacs.d, init.el, and .emacs . . . . . . . . .
Major Modes and Minor Modes
. . . . . .
First Steps
Installing and Starting Emacs . . . . . . . . . . .
Starting Emacs . . . . . . . . . . . . . . . .
The Emacs Interface
. . . . . . . . . . . . . . .
Keys . . . . . . . . . . . . . . . . . . . . . . . .
Caps Lock as Control
. . . . . . . . . . . .
M-x: Execute Extended Command . . . . .
Universal Arguments . . . . . . . . . . . .
Discovering and Remembering Keys . . . .
Configuring Emacs . . . . . . . . . . . . . . . .
The Customize Interface . . . . . . . . . .
Evaluating Elisp Code . . . . . . . . . . . .
The Package Manager . . . . . . . . . . . .
Color Themes . . . . . . . . . . . . . . . .
Getting Help . . . . . . . . . . . . . . . . . . .
The Info Manual
. . . . . . . . . . . . . .
Apropos . . . . . . . . . . . . . . . . . . .
The Describe System . . . . . . . . . . . .
The Theory of Movement
The Basics . . . . . . . . . . . . . . . . . . . . .
C-x C-f: Find file . . . . . . . . . . . . . . .
C-x C-s: Save Buffer . . . . . . . . . . . . .
C-x C-c: Exits Emacs . . . . . . . . . . . . .
C-x b: Switch Buffer . . . . . . . . . . . . .
C-x k: Kill Buffer
. . . . . . . . . . . . . .
ESC ESC ESC: Keyboard Escape . . . . . . . .
C-/: Undo . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
Working with Other Windows . . . . . . .
Frame Management . . . . . . . . . . . . . . . .
Elemental Movement . . . . . . . . . . . . . . .
Navigation Keys . . . . . . . . . . . . . . .
Moving by Character . . . . . . . . . . . .
Window Management
Moving by Line . . . . . . . . . . . . . . .
Moving by Word . . . . . . . . . . . . . .
Moving by S-Expressions . . . . . . . . . .
Other Movement Commands
. . . . . . .
Scrolling . . . . . . . . . . . . . . . . . . .
Bookmarks and Registers . . . . . . . . . . . . .
Selections and Regions . . . . . . . . . . . . . .
Selection Compatibility Modes . . . . . . .
Setting the Mark . . . . . . . . . . . . . .
Searching and Indexing . . . . . . . . . . . . . .
Isearch: Incremental Search . . . . . . . . .
Occur: Print lines matching an expression .
Imenu: Jump to definitions . . . . . . . . .
Helm: Incremental Completion and Selection
IDO: Interactively DO Things . . . . . . .
Other Movement Commands
. . . . . . . . . .
Conclusion . . . . . . . . . . . . . . . . . . . .
The Theory of Editing
Killing and Yanking Text . . . . . . . . . . . . .
Killing versus Deleting . . . . . . . . . . .
Yanking Text
. . . . . . . . . . . . . . . .
Transposing Text . . . . . . . . . . . . . . . . .
C-t: Transpose Characters . . . . . . . . . .
M-t: Transpose Words . . . . . . . . . . . .
C-M-t: Transpose S-expressions . . . . . . .
Other Transpose Commands . . . . . . . .
Filling and Commenting . . . . . . . . . . . . .
Filling . . . . . . . . . . . . . . . . . . . .
Commenting . . . . . . . . . . . . . . . .
Search and Replace . . . . . . . . . . . . . . . .
Case Folding . . . . . . . . . . . . . . . . .
Regular Expressions . . . . . . . . . . . . .
Changing Case . . . . . . . . . . . . . . . . . .
Counting Things
. . . . . . . . . . . . . . . . .
Text Manipulation . . . . . . . . . . . . . . . .
Editable Occur . . . . . . . . . . . . . . . .
Deleting Duplicates . . . . . . . . . . . . .
Flushing and Keeping Lines . . . . . . . . .
Joining and Splitting Lines
. . . . . . . . .
Whitespace Commands . . . . . . . . . . .
Keyboard Macros . . . . . . . . . . . . . . . . .
Basic Commands
. . . . . . . . . . . . . .
Advanced Commands . . . . . . . . . . . .
Text Expansion . . . . . . . . . . . . . . . . . .
Abbrev . . . . . . . . . . . . . . . . . . . .
DAbbrev and Hippie Expand . . . . . . . .
Indenting Text and Code . . . . . . . . . . . . .
. . . . . . . . . .
RET: Indenting New lines
TAB: Indenting the Current Line
. . . . . .
Indenting Regions . . . . . . . . . . . . . .
Sorting and Aligning . . . . . . . . . . . . . . .
Sorting . . . . . . . . . . . . . . . . . . . .
Aligning . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
Zapping Characters . . . . . . . . . . . . .
Spell Checking . . . . . . . . . . . . . . .
uoted Insert . . . . . . . . . . . . . . . .
Other Editing Commands
The Practicals of Emacs
Exploring Emacs
. . . . . . . . . . . . . . . . .
Reading the Manual . . . . . . . . . . . . .
Dired: Files and Directories
Using Apropos
C-h: Exploring Prefix keys
C-h k: Describe what a key does
C-h m: Finding mode commands
. . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . .
. . . . . .
Working with Log Files . . . . . . . . . . . . . .
Browsing Other Files . . . . . . . . . . . .
TRAMP: Remote File Editing . . . . . . . . . .
Multi-Hops and User Switching . . . . . .
. . . . . . . . . . .
Navigation . . . . . . . . . . . . . . . . . .
Marking and Unmarking . . . . . . . . . .
Operations . . . . . . . . . . . . . . . . . .
Working Across Directories . . . . . . . . .
. . . . . . . . . . . . . . . . .
Compiling in Emacs . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
M-x shell: Shell Mode . . . . . . . . . . . .
M-x ansi-term: Terminal Emulator
. . . . .
. . . . . . . . . .
M-x eshell: Emacs’s Shell
Shell Commands
Shells in Emacs
Conclusion
Other Resources
. . . . . . . . . . . . . . . . .
Chapter
Introduction
“I’m using Linux. A library that emacs uses to
communicate with Intel hardware.”
– Erwin, emacs, Freenode.
Thank You
Thank you for purchasing Mastering Emacs. This book has
been a long time coming. When I started my blog, Master-
ing Emacs, in , it was at the recommendation of a good
friend, Lee, who suggested that I share my thoughts on
Emacs and work flow in Emacs. At the time I had accrued
in an org mode file titled blogideas.org a large but random
assortment of ideas and concepts that I’d learned about and
wished someone had taught me. The end result of that file
is the blog and now this book.
Special Thanks
Introduction
I would like to thank the following people for
their encouragement, advice, suggestions and
critiques:
Akira Kitada, Alvaro Ramirez, Arialdo Mar-
tini, Bob Koss, Catherine Mongrain, Chandan
Rajendra, Christopher Lee, Daniel Hannaske,
Edwin Ong, Evan Misshula, Friedrich Paetzke,
Gabriela Hajduk, Gabriele Lana, Greg Sieranski,
Holger Pirk, John Mastro, John Kitchin, Jonas
Enlund, Konstantin Nazarenko, Lee Cullip,
Luis Gerhorst, Lukas Pukenis, Manuel Uberti,
Marcin Borkowski, Mark Kocera, Matt Wilbur,
Matthew Daly, Michael Reid, Nanci Bonfim,
Oliver Martell, Patrick Mosby, Patrick Martin,
Sebastian Garcia Anderman, Stephen Nelson-
Smith, Steve Mayer, Tariq Master, Travis
Jefferson, Travis Hartwell.
Like a lot of people, I was thrust into the world of Emacs
without knowing anything about it; in my case it was in
my first year of University where the local computer soci-
ety was made up primarily of Vim users. It was explained
to me, in no uncertain terms, that “you use Vim — that’s
it.” Not wanting to be told what to do, I picked the polar
opposite of Vim and went with Emacs.
Emacs proved to be a stable and reliable editor in all those
years, but it was a tough one to get to know. Despite the
extensive user documentation, it never helped me to learn
and understand Emacs.