Skip to content
GitHub Twitter

Emacs Chapter-1

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<br>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 EmacsEmacs 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 ModeEmacs 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 BuffersUnderstanding Emacs' terminology is crucial:
TermDescription
FrameEquivalent to a traditional window in a graphical desktop environment.
WindowA pane within a frame, used to display different buffers.
BufferA temporary space where files, text, and command outputs are displayed and edited.

Essential KeybindingsEmacs is designed for efficient keyboard navigation. Some fundamental keybindings include:
KeybindingAction
Ctrl-x Ctrl-fOpen a file
Ctrl-x Ctrl-sSave the current file
Ctrl-x bSwitch between buffers
Ctrl-x Ctrl-bList buffers
Ctrl-x kClose (kill) a buffer
Ctrl-wCut (Kill text)
Ctrl-yPaste (Yank text)
M-wCopy text
Ctrl-/Undo (forward-slash key next to right-shift key)
Ctrl-x oSwitch window
Ctrl-gCancel an operation
Esc-Esc-EscKeyboard-escape-quit — closes all popped up windows except the current
Navigating Through Words, Lines, and TextWe can use the same key-bindings as we move the cursor in terminal to the beginning or to the end.
KeybindingAction
Ctrl-aMove cursor to the beginning of the line
Ctrl-eMove cursor to the end of the line
Ctrl + Right ArrowMove cursor one word forward
Ctrl + Left ArrowMove cursor one word backward

Major and Minor Modes
  • Major Modes: Determine how Emacs interacts with different file types (e.g., Python mode for .py files, Org mode for .org files).
    M-x html-mode
    
  • Minor Modes: Optional enhancements that provide additional functionality, such as line highlighting.
    M-x hl-line-mode
    

Customizing EmacsCustomization is a key strength of Emacs. There are two main ways to configure it:
  1. Using Customize UI (M-x customize): A graphical interface for modifying settings.
  2. Editing the Init File (~/.emacs or ~/.emacs.d/init.el): A script where users can write Emacs Lisp to define keybindings, load themes, and extend functionality.

Learning MoreEmacs has a built-in help system:
KeybindingAction
C-h tOpen the Emacs tutorial
C-h kDescribe a keybinding
C-h fDescribe a function
C-h vDescribe a variable

Continues…