Emacs Decoded: The Ultimate Guide to Navigating, Editing, and Customizing Your Text Environment

Rita KairuRita Kairu
3 min read

Emacs is a powerful and extensible text editor that has been around for decades.

It's known for its flexibility and is often used by programmers and system administrators.

This guide will cover some basic commands and concepts to help you get started with Emacs.

Installing Emacs

Linux

On most Linux distributions, you can install Emacs using the package manager. For example, on Debian-based systems like Ubuntu:

sudo apt-get update
sudo apt-get install emacs

macOS

On macOS, you can use Homebrew to install Emacs:

brew install emacs

Windows

For Windows, you can download Emacs from the official website: Emacs for Windows

Basic Navigation

  • Opening Emacs: Simply type emacs in the terminal.

  • Exiting Emacs: To exit Emacs, press Ctrl-x Ctrl-c.

  • Creating a new file: Press Ctrl-x Ctrl-f to open a new file. Type the filename and press Enter.

  • Saving a file: Press Ctrl-x Ctrl-s to save the current file.

Modes

Emacs has different modes for different tasks. The two main modes are:

  • Normal mode: This is the default mode for navigation and basic text editing.

  • Insert mode: To enter insert mode, press i. In insert mode, you can type and edit text like in a regular text editor.

Basic Editing

  • Moving the cursor:

    • Use arrow keys for basic movement.

    • Ctrl-f: Move forward one character.

    • Ctrl-b: Move backward one character.

    • Ctrl-n: Move to the next line.

    • Ctrl-p: Move to the previous line.

  • Deleting text:

    • Backspace: Delete the character before the cursor.

    • Ctrl-d: Delete the character under the cursor.

    • Ctrl-k: Delete from the cursor position to the end of the line.

Searching

  • Search forward: Press Ctrl-s, type your search query, and press Enter. Repeat Ctrl-s to find the next occurrence.

  • Search backward: Press Ctrl-r, type your search query, and press Enter. Repeat Ctrl-r to find the previous occurrence.

Advanced Editing

  • Copy and Paste:

    • Ctrl-space: Set the mark for the beginning of the selection.

    • Ctrl-w: Cut (kill) the selected text.

    • Meta-w: Copy (kill-ring-save) the selected text.

    • Ctrl-y: Yank (paste) the cut/copied text.

  • Undo and Redo:

    • Ctrl-/ or Ctrl-x u: Undo.

    • Meta-/ or Ctrl-x Ctrl-/: Redo.

Customizing Emacs

Emacs is highly customizable. You can create a configuration file called .emacs or init.el in your home directory to add custom settings. For example:

;; Example configuration to enable line numbers
(global-linum-mode t)

Conclusion

There's more to Emacs than only the basics mentioned above. It has a steep learning curve, but it rewards users with unparalleled flexibility and efficiency once mastered.

You can explore more Emacs commands in the built-in tutorials (Ctrl-h t) and documentation (Ctrl-h i) for more in-depth information.

Happy editing!

0
Subscribe to my newsletter

Read articles from Rita Kairu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rita Kairu
Rita Kairu

A coding civil engineer!