Why Use Emacs in Linux: A Practical Guide
In this article
Yes, you should use Emacs in Linux if you want a highly customizable, extensible text editor that can handle everything from coding to email, all within a single, powerful interface. Emacs has been a staple of Unix-like systems for decades, and its flexibility is unmatched. This guide walks you through the benefits and how to get started.
What You'll Need
- A Linux system (any mainstream distribution like Ubuntu, Fedora, or Debian).
- Terminal access (usually via Ctrl+Alt+T).
- Basic familiarity with the command line (navigating directories, running commands).
- Internet connection for installing packages (if not already installed).
Step-by-Step
- Install Emacs. On Debian/Ubuntu, run
sudo apt install emacs. On Fedora, usesudo dnf install emacs. On Arch,sudo pacman -S emacs. Alternatively, you can install Emacs from your distribution's graphical software center. - Launch Emacs. Type
emacsin the terminal to start it in the terminal, oremacs &to launch it as a GUI window (if you have a graphical environment). The first time, you'll see a welcome buffer with a tutorial link. - Learn the basic keybindings. Emacs uses modifier keys heavily. The most important are
C-x(Ctrl+x),C-c(Ctrl+c), andM-x(Alt+x). For example,C-x C-ssaves the file,C-x C-fopens a file, andC-x C-cquits Emacs. PressC-h tto launch the interactive tutorial. - Open a file. Press
C-x C-f, then type the path to a file (e.g.,~/Documents/notes.txt) and press Enter. If the file doesn't exist, Emacs creates it. - Edit and save. Just start typing to edit. To save, press
C-x C-s. To save as a different name, pressC-x C-w. - Use multiple buffers. Emacs manages files in "buffers." Press
C-x bto switch buffers,C-x kto kill a buffer, andC-x C-bto list all buffers. - Install packages. Emacs has a built-in package manager. Press
M-x package-list-packagesto see available packages. To install, move the cursor to a package and pressito mark it, thenxto execute the installation. Popular packages likemagit(Git interface) andcompany(autocompletion) are available. - Customize Emacs. Your configuration lives in
~/.emacsor~/.emacs.d/init.el. You can start by pressingM-x customizeto change settings graphically. For more advanced tweaks, edit the init file with Emacs itself. - Use Emacs for programming. Emacs has built-in support for many languages. Open a source file (e.g.,
main.py) and Emacs automatically enters the appropriate major mode (Python mode). UseM-x compileto run a build command, andM-x shellto open a terminal inside Emacs. - Explore Org-mode. Org-mode is a powerful outlining and note-taking tool. Press
C-x C-fand create a file with a.orgextension. Start typing* Headingto create a headline. UseTabto fold/unfold sections. This is great for todo lists and documentation.
Common Mistakes
- Not using the tutorial. Many beginners skip the built-in tutorial and then struggle with basic commands. Take 20 minutes to go through
C-h t. - Confusing Emacs with Vim. Emacs does not have modal editing by default. If you expect Vim-style modes, you'll be frustrated. You can install Evil mode to get Vim bindings, but that's an add-on.
- Overcustomizing too early. Spending hours tweaking config before learning basics is counterproductive. Start with the default setup, then add packages as needed.
- Forgetting to save. Emacs doesn't autosave by default (though it can be enabled). Get into the habit of pressing
C-x C-sfrequently.
Tips
- Learn incrementally. Master a few keybindings each day. You don't need to memorize everything at once.
- Use the menu bar. If you're in the GUI, the menu bar (File, Edit, Options) can help discover commands. In the terminal, you can use
M-xand type the command name. - Use
C-gto cancel. If you get stuck in a command, pressC-gto abort it. - Take advantage of built-in help.
C-h ktells you what a key does,C-h fdescribes a function, andC-h vexplains a variable. - Back up your config. Keep your
init.elin a version control repository (like Git) so you can track changes and sync across machines.
Troubleshooting
If Emacs doesn't start, first check that it's installed correctly by running emacs --version. If the command isn't found, reinstall it. If Emacs opens but looks odd (e.g., no colors), your terminal may not support 256 colors—try running emacs -nw in a terminal that supports colors, or install a terminal like GNOME Terminal.
If a package fails to install, make sure you have an internet connection and that the package repository is accessible. Sometimes you need to update the package list first: M-x package-refresh-contents.
If Emacs freezes, it might be due to a runaway command. Press C-g to interrupt. If that doesn't work, you can kill the process from another terminal with pkill emacs (this will lose unsaved changes).
If your customizations break Emacs, start with a clean config: emacs -Q (no init file) to see if the problem persists. Then, comment out recent changes in your init file.
Frequently Asked Questions
Is Emacs really better than Vim?
It's a matter of preference. Emacs is more extensible and has a gentler learning curve for non-modal editing. Vim is more lightweight and has modal editing. Both are powerful; try both and see which fits your workflow.
Can I use Emacs for things other than text editing?
Yes, Emacs can run a shell, read email (with packages like Gnus), browse files, manage calendars, and even play games. It's essentially an operating system inside an editor.
How do I exit Emacs?
Press C-x C-c. If you have unsaved changes, Emacs will prompt you to save them before quitting.
Does Emacs work in the terminal and GUI?
Yes, Emacs runs in both. The GUI version (usually started with emacs without -nw) offers menus and mouse support. The terminal version (emacs -nw) is useful for remote sessions via SSH.
How do I change the theme?
Use M-x load-theme and select from built-in themes like tango-dark or leuven. To make it permanent, add (load-theme 'tango-dark t) to your init file.
Is Emacs available for other operating systems?
Yes, Emacs runs on Windows and macOS as well, but it's most naturally integrated with Linux and other Unix-like systems. The keybindings and commands are identical across platforms.