The Absolute Beginner's Guide to Emacs
"A wise teacher doesn't just tell you what they know; they help you discover the wisdom that's already inside you."
— Kahlil Gibran, The Prophet on Teaching
Introduction
Emacs is one of the most powerful and flexible text editors available, often praised for its extensibility and deep customization options. This guide is designed for absolute beginners, providing essential knowledge to get started with Emacs and utilize its core features effectively.
Installing Emacs
Emacs can be installed on various operating systems:
- GNU/Linux: Available in most package managers as
emacs.
apt install emacs # For Debian and its based distributions
Graphical vs. Terminal Mode
Emacs can run in two primary modes:
- Graphical Mode: Provides a full GUI experience, including menus and toolbars.
- Terminal Mode: Runs inside a terminal for lightweight usage, invoked with
emacs -nw.
Both modes share the same functionality, with the primary difference being user interface elements.
Emacs Windows, Frames, and Buffers
Understanding Emacs' terminology is crucial:
| Term | Description |
|---|---|
| Frame | Equivalent to a traditional window in a graphical desktop environment. |
| Window | A pane within a frame, used to display different buffers. |
| Buffer | A temporary space where files, text, and command outputs are displayed and edited. |
Essential Keybindings
Emacs is designed for efficient keyboard navigation. Some fundamental keybindings include:
| Keybinding | Action |
|---|---|
Ctrl-x Ctrl-f | Open a file |
Ctrl-x Ctrl-s | Save the current file |
Ctrl-x b | Switch between buffers |
Ctrl-x Ctrl-b | List buffers |
Ctrl-x k | Close (kill) a buffer |
Ctrl-w | Cut (Kill text) |
Ctrl-y | Paste (Yank text) |
M-w | Copy text |
Ctrl-/ | Undo (forward-slash key next to right-shift key) |
Ctrl-x o | Switch window |
Ctrl-g | Cancel an operation |
Esc-Esc-Esc | Keyboard-escape-quit — closes all popped up windows except the current |
Navigating Through Words, Lines, and Text
We can use the same key-bindings as we move the cursor in terminal to the beginning or to the end.
| Keybinding | Action |
|---|---|
Ctrl-a | Move cursor to the beginning of the line |
Ctrl-e | Move cursor to the end of the line |
Ctrl + Right Arrow | Move cursor one word forward |
Ctrl + Left Arrow | Move cursor one word backward |
Major and Minor Modes
Major Modes: Determine how Emacs interacts with different file types (e.g., Python mode for
.pyfiles, Org mode for.orgfiles).M-x html-modeMinor Modes: Optional enhancements that provide additional functionality, such as line highlighting.
M-x hl-line-mode
Customizing Emacs
Customization is a key strength of Emacs. There are two main ways to configure it:
- Using Customize UI (
M-x customize): A graphical interface for modifying settings. - Editing the Init File (
~/.emacsor~/.emacs.d/init.el): A script where users can write Emacs Lisp to define keybindings, load themes, and extend functionality.
Learning More
Emacs has a built-in help system:
| Keybinding | Action |
|---|---|
C-h t | Open the Emacs tutorial |
C-h k | Describe a keybinding |
C-h f | Describe a function |
C-h v | Describe a variable |
Continues…