Emacs is one of the oldest text editors with ongoing development, providing rich and powerful features that can be further extended using plugins.
It provides a wide range of functionalities that can be very useful for programmers and Linux administrators while modifying the configuration file.
|Root or Sudo Privileges
|Ubuntu, Manjaro, Fedora, etc.
|Yes (for installation)
How to Install Emacs in Linux
Yes, I agree with you that this tool is aged and should be included in Linux distributions.
Still, it was not included; however, it is available in major Linux repositories, from which you can install it using the following command.
$ sudo apt install emacs -y #For Debian/Ubuntu/Pop!_OS
$ sudo dnf install emacs -y #For Fedora/AlmaLinux/Red Hat
$ sudo pacman -Sy emacs #For Arch/Manjaro/EndeavourOS
If you directly execute the “
emacs” command, it will open the GUI version of this application.
However, today you will learn mostly on the command line. So, execute the following command to open the command-line version of the Emacs editor.
$ emacs -nw
From here, you can navigate using the arrow key. Apart from that, if you want to create a new file, navigate to the “Visit New File” link using the arrow keys and press the “enter” key.
It will ask for the existing file location from the directory, which you can easily navigate using the Tab and arrow keys.
However, I will create a new file (ex: “file.txt”) that does not exist in my home directory and press the “enter” key to open a new file.
From the above window, if you changed your mind and want to open an existing file, press “Ctrl+x” and then the “Ctrl+f” shortcut key simultaneously.
Above, you can specify the full file path or press the “enter” key at the current path “
~/” to open the emacs file manager and navigate through arrow keys to open the file from your system.
However, I stick with my previously created file (ex: “file.txt”) and started adding new content.
Currently, your file is automatically saved in your home directory in “
#yourfilename#” file format (ex: “
If you are done with editing and want to save the file, press “Ctrl+x” and then “Ctrl+s” simultaneously.
To close the editing window referring to the emacs editor, press “Ctrl+x” and then the “Ctrl+c” shortcut keys simultaneously.
In the future, if you want to open the same file, specify the path of that file to the “
emacs” command as shown.
$ emacs file.txt -nw
Modify the file and save with “Ctrl+x” and then the “Ctrl+s” shortcut key, and press “Ctrl+x” and then “Ctrl+c” to quit the Emacs editor.
You might be confused with this manner of editing files. However, you can watch the below video to understand it more easily.
Also, don’t forget to take a look at the following cheat sheet.
Emacs Cheat Sheet
- C = Control Key
- M = Meta Key (Alt on PCs, Option on Macs)
|Cancel any in progress keybinding/shortcut command.
|Save current buffer.
|Switch to a different buffer.
|Kill/close current buffer.
|Open a file.
|Undo the last action.
|Move to beginning of buffer/file.
|Move to end of buffer/file.
|Move one screen forward.
|Move one screen backward.
|Center screen on position at cursor.
|Move to beginning of the line.
|Move to end of line.
|Move to the next line.
|Move to the previous line.
|Go to line.
|Move forward one word.
|Move backward one word.
|Move forward one character.
|Move backward one character.
|Regex search for text in the current buffer and move to it. Press C-s again to move to next match.
|Same as C-s, but search in reverse.
|Search and replace.
Kill Ring (Copy/Cut/Paste)
|Create a region (select). Use movement keys to expand the region selected. Then use copy/cut commands below.
|Copy region to kill ring (copy).
|Kill region (cut).
|Cycle through kill ring after yanking/pasting. This is like a copy/paste clipboard.
|Kill/delete word starting at cursor (cut).
|Kill/delete line starting at cursor (cut).
|New line and indent, equivalent to enter followed by tab.
|Delete all spaces and tabs around point.
|Delete the next character.
|Delete previous word.
|C-x space (use movement keys to select up/down).
C-x r t (type key to insert, then Enter)
|Swap two characters at the point/cursor.
|Change the word at the point/cursor to uppercase.
|Change the word at the point/cursor to lowercase.
|C-u n char
|Insert ‘n’ (a number) copies of ‘char’ (a character).
|C-h k key-binding
|Describe the function bound to the key binding. To get this to work, you actually perform the key sequence after typing C-h k.
That’s all for now. If you have anything else that needs to be added to this article, please let us know in the comment section.