Emacs is a powerful and extensible text editor that has been a staple in the development community for decades. Created by Richard Stallman as part of the GNU Project, Emacs offers a wide array of features that make it more than just a text editor. Whether you are writing code, editing text files, or managing tasks, Emacs can be customized to suit your needs.
Emacs is often described as an "operating system disguised as an editor." This might sound exaggerated, but once you delve into its vast ecosystem of commands, extensions, and customizations, you'll understand why. Emacs can be daunting for beginners due to its non-intuitive interface and keybindings, but with practice, it becomes a powerful tool for text editing, programming, and much more.
This tutorial will walk you through the essentials of using Emacs, from installation to advanced features, ensuring you gain a solid foundation to build upon.
To begin using Emacs, you first need to install it on your Linux system (you can try our Linux VPS hosting for your projects). Emacs is available in the repositories of most major Linux distributions, making the installation process straightforward.
sudo apt update
sudo apt install emacs
sudo dnf install emacs
sudo pacman -S emacs
Once installed, you can start Emacs by typing emacs
in your terminal.
Emacs may feel unfamiliar if you're used to other text editors. Here's a quick guide to basic navigation:
Move the cursor: Use the arrow keys or Ctrl + f
(forward), Ctrl + b
(backward), Ctrl + n
(next line), and Ctrl + p
(previous line).
Scroll through the text: Use Alt + v
to scroll up and Ctrl + v
to scroll down.
Jump to the beginning or end of the line: Use Ctrl + a
to move to the beginning and Ctrl + e
to move to the end.
Editing text in Emacs is straightforward once you get the hang of the keybindings. Here’s how you can start.
To open a file in Emacs, use the Ctrl + x Ctrl + f
command, then type the file path and press Enter.
You can start typing immediately to insert text.
To delete characters:
Ctrl + d
.Backspace
.To save the file you’re working on:
Ctrl + x Ctrl + s
.Ctrl + x Ctrl + w
, then type the new file name and press Enter.Emacs is driven by keybindings, which can be a challenge for new users. Here are some essential commands:
Ctrl + /
or Ctrl + _
.Ctrl + w
.Alt + w
.Ctrl + y
.These keybindings allow you to perform text operations efficiently. As you become more comfortable with Emacs, you can explore more advanced keybindings and commands.
One of Emacs's strengths is its customizability. You can modify almost every aspect of Emacs to better suit your workflow. You can create and edit the .emacs
or init.el
file. This is how it is done in Ubuntu.
1. Check if the .emacs
or init.el
file exists in your home directory:
ls -a ~ | grep -E '\.emacs|init\.el'
If nothing is returned, the file doesn't exist.
2. If the file doesn't exist, you can create it manually. Decide whether you want to use the .emacs
file or the init.el
file (located in the .emacs.d
directory). Either will work, but init.el
is more common in modern configurations.
To create .emacs:
touch ~/.emacs
3. The .emacs
or init.el
file is where you can place custom configurations. To edit this file:
emacs ~/.emacs
Here, you can add commands to change Emacs's behavior. For example, to enable line numbers by default, add the following line:
(global-display-line-numbers-mode t)
Emacs has a vast ecosystem of packages that extend its functionality. To install packages, you’ll first need to enable the package manager:
1. Open the .emacs
file.
2. Add the following lines to initialize the package system:
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
3. Save and restart Emacs.
4. Use Alt + x
and type package-install
, then the name of the package you want to install.
Emacs allows you to open and work with multiple files simultaneously using buffers.
Ctrl + x b
, type the buffer name, and press Enter.Ctrl + x Ctrl + b
.Ctrl + x 2
.Ctrl + x 3
.Ctrl + x 0
.Emacs shines when it comes to automation and extensibility.
Macros in Emacs allow you to record a series of commands and replay them.
Ctrl + x (
.Ctrl + x )
.Ctrl + x e
.Extensions, or packages, enhance Emacs's functionality. For instance, Magit is a popular Git interface for Emacs.
Alt + x
and type package-install
, then magit
.Emacs integrates well with version control systems like Git.
Magit is a powerful Git interface for Emacs. After installing it, you can:
Open Magit: Use Alt + x
and type magit-status
.
Stage changes: Navigate to the file and press s
.
Commit changes: Press c
then c
to commit.
Here are some tips to help you become more efficient in Emacs:
Learn the keybindings: Familiarize yourself with the essential keybindings to improve your speed.
Use Emacs’s help system: Use Ctrl + h
to access help within Emacs.
Customize your environment: Spend time tweaking your .emacs
file to create a comfortable environment.
Emacs is a versatile and powerful tool that can greatly enhance your productivity once you overcome its initial learning curve. By following this tutorial, you should now have a solid understanding of how to install, navigate, and customize Emacs to suit your needs. Whether you are coding, writing, or managing tasks, Emacs is a tool that can grow with you, offering limitless possibilities for customization and efficiency.
Start exploring Emacs today, and discover how this seemingly simple text editor can become an indispensable part of your workflow.
This tutorial provides a comprehensive guide for beginners on how to use the Emacs editor in Linux. By covering everything from basic navigation to advanced features, users can develop a strong foundation to leverage Emacs's full potential.