Emacs is a highly extensible and customizable text editor primarily used for writing and editing plain text files and is known for its powerful features and adaptability.
What sets it apart from other text editors is its editing capabilities. Emacs offers a diverse array of keyboard shortcuts that enable efficient manipulation of text. Additionally, it allows users to work on multiple files or views simultaneously without opening numerous instances of the editor.
With all such use cases and benefits, emacs is helpful, but only if you know how to use it properly. That’s why this article is here to help guide you through the emacs command on Linux for beginners. So, let’s get started.
Installing Emacs on Linux
The process of setting up Emacs on a Linux system is simple. You can make use of the built-in package manager in your Linux distribution to install Emacs, depending on the specific distribution you are using.
1: Debian and Ubuntu
For Debian-based distributions like Debian itself and Ubuntu, the apt package manager is used. Launch your terminal application and input the following command:
By executing this command, you will install the most up-to-date, stable version of Emacs that is accessible within your distribution’s repositories.
2: Fedora
In case you are utilizing Fedora, the appropriate package manager to use is dnf. To install Emacs, simply open your terminal and input the following command:
3: Red Hat and CentOS
For Red Hat and CentOS, the yum package manager is used. Open your terminal and type:
Verifying the Installation
Once the installation process is finished, you can confirm the successful installation of Emacs by executing the following command in your terminal:
Upon executing this command, the version number of Emacs should be displayed, thereby confirming its successful installation on your system.
Emacs for beginners
Now that we have installed Emacs on the Linux system, let’s get familiar with the basics of using this powerful text editor.
To launch Emacs, open your terminal and simply type emacs. This command opens Emacs with its graphical interface. If you prefer to use Emacs within the terminal, you can launch it in terminal mode by using the command:
Basic Navigation
Navigating within Emacs can be done using both the arrow keys and shortcut commands:
- CTRL + p : Move up one line (similar to pressing the up arrow).
- CTRL + n : Move down one line (similar to pressing the down arrow).
- CTRL + f : Move forward one character (similar to pressing the right arrow).
- CTRL + b : Move backward one character (similar to pressing the left arrow).
1: Opening and Closing Files
To open a file in Emacs, use the CTRL + x followed by CTRL + f command, then type the file name and press Enter. In case the file doesn’t exist, Emacs will create a new file using the given name.
To close a file, use the CTRL + x followed by CTRL + k command.
2: Editing Text
Editing text in Emacs is similar to other text editors but with different shortcuts:
- CTRL + d : Erase the character found under the cursor.
- CTRL + k : Erase from the current cursor position to the end of the line.
- CTRL + w : Cut the selected text.
- ALT + w : Copy the selected text.
- CTRL + y : Paste the copied or cut text.
3: Saving Files
To save the file you are working on, use the CTRL + x followed by CTRL + s command.
4: Exiting Emacs
To exit Emacs, use the CTRL + x followed by CTRL + c command. When there are any unsaved changes, Emacs will ask you to save them before you exit.
5: Getting Help
Emacs has an extensive built-in help system. Press CTRL + h followed by t to open a tutorial. For a list of commands, press CTRL + h followed by b.
Conclusion
Emacs is a long-standing text editor that offers great flexibility, allowing you to customize it according to your preferences and needs. It can be tricky to learn because there are so many shortcuts and features, but once you get familiar with emacs commands on Linux for beginners, it’s a super powerful tool that can make your work easier, no matter if you are coding, writing, or managing files.