What are command line editors?
These are simply text editors that are designed to be used in the command line in your computer.
These editors are used to edit text and code when using the command line. They are provided to give you a rich text/code editing environment in your CLI.
These editors are typically fast and easy to use, it simply requires a predefined set of keybindings (two or more keyboards keys) to be pressed to be able to navigate through it.
There are quite a handful of command line editors out there such as: emacs, vim, nano, Neovim, gedit, JED etc. But today we're only going to be taking a look at the EMACS editor.
What is EMACS?
This is one of the most commonly used text editor out of many command line text editors out there and it stands for (Editor MACroS).
It comes nicely integrated for almost any imaginable programming task out there, equipped with rich syntax highlighting. It is known for its extensive set of features and extensibility, and is widely used in the programming and Unix communities. It features efficient commands for common but complex actions and for the plugins and configuration hacks that have developed around it for nearly 40 years. It is also very beginner friendly to use.
To start using EMACS, you'll first need to download and install it on your computer. It is available for most operating systems, including Windows, Linux, and macOS.
To install emacs, you can follow the appropriate steps according to your operating system:
Windows:
You can download the latest version of emacs for Windows from the official website and then run the installer.
MacOS:
You can install emacs using Homebrew package manager by running the command brew install emacs
in the terminal.
Linux:
The process to install emacs will vary depending on the distribution of Linux you are using. For example, on Ubuntu or Debian you can use the command sudo apt-get install emacs
or just apt install emacs
in the terminal to install emacs.
To open the editor after installation, we use the command emacs
, followed by the name of the file you want to open or create.
Like this:
emacs filename
This would open up the file in the editor in your terminal, and you can get started with editing your texts.
Different commands (keybindings) for Navigating EMACS
EMACS uses a set of keybindings for navigation and editing, rather than a graphical user interface and your typical trackpad or mouse.
Basic EMACS Navigations
opening a file from within EMACS:
C-x C-f
short forCtrl + x Ctrl + f
Saving a file:
C-x C-s
short forCtrl + x Ctrl + s
Cutting an entire line:
C-k
short forCtrl + k
Pasting into the file:
C-y
short forCtrl + y
Searching forward for a string:
C-s
Short forCtrl + s
Undoing last change:
C-x u
short forCtrl + x u
To redo the change, just use that command again.Quitting EMACS:
C-x C-c
short forCtrl + x Ctrl + c
Basic cursor movement keys
C- means the ctrl
key, use it along with the other letters to perform the desired action
Move cursor forward
C-f
Move cursor backward
C-b
Move cursor to the next line
C-n
Move cursor to the previous line
C-p
Move cursor to the beginning of line
C-a
Move cursor to the end of line
C-e
Working with Buffers and Windows
EMACS also allows you to work with multiple open files (buffers) at the same time, and navigate between them using keybindings.
Here are a few of them:
switch to another buffer:
C-x b
split the current window into two:
C-x 2
close the current window:
C-x 0
list all buffers:
C-x C-b
kill (close) the current buffer:
C-x k
save all open buffers:
C-x s
save the current buffer:
C-x C-s
switch to the previous/next buffer in the buffer list:
C-x left/right arrow
switch to a different buffer in another window:
C-x 4 b
display the buffer list in another window:
C-x 4 C-o
switch to a different buffer in a new frame:
C-x 5 b
close the current frame and its associated buffer(s):
C-x 5 0
These are some basic features of EMACS, it has a lot more functionality, you can explore and customize it according to your needs.
That's it for this article guys, hope you found it helpful, don't forget to leave a like if you did, or a comment if you have any questions 😊 see you in part 2 of the command line editors.
Top comments (2)
Interesting but very short
Thanks for the feedback 😊...i would try to add more information in the article