Choosing a Linux Text Editor

Battlefield History

Programmers can have some pretty strong opinions about their preferred environment to work. Open vs. closed; standings vs. sitting; IDE vs. other IDE; Atom vs. Visual Studio. But few of these arguments have inspired the passions of the editor wars. Proponents of an editor can sometimes reach a level of religious fanaticism.

My opinion, which should not be any surprise to people who are familiar with me, is that it is just characters on a screen and who really cares how you manipulate them? I am only on the second paragraph of this blog, and I have already used three different text editors to edit this blog. The passions involved are completely out of range for different products that all work fairly. But, in the interest of thoroughness, I plan to cover the three of the primary Linux text editors.

The war between proponents of two of these editors, vi and Emacs, goes back to the late 1980's, but text editor wars may actually go back to the end of the 1960's with even more basic text editing software. Those programs would eventually evolve into the more fulsome text editors that developed in the late 20th Century and are still largely in use today. For someone just starting out in Linux, it is probably best to focus on one editor, learn it well, and become the best developer one can be. But, it is not that simple. Choosing a text editor is not just installing a program, it is choosing a side in a war.

Vim

Vim is a clone of the earlier Vi editor, but with added features. Vim gets its name from Vi; it means VI iMproved. While Vi has been around since the 1970's, Vim was released as free and open-source software in 1991. Vim can be opened with the simple vim command, but that really just brings up a description screen. Better would be to provide a file directory and name as an argument. Providing an existing file (vim myFile.html) will open it in Vim, while providing a new file name will create it as a .txt swap file until you formally save it.

Vim has seven modes total, but there are really only three we need to worry about for this basic introduction. Normal mode is how a file is displayed when the documented is opened in Vim. It is useful for reading a file, but is frankly less useful than simple Linux commands like more myFile.txt, less myFile.txt, or cat myFile.txt.

The most useful for writing is the insert mode, which acts most like a word processor or code editor. The target at which your are entering or deleting text is displayed clearly on the screen and it can be moved with the arrows on the keyboard or the 'h','j','k', and 'l' keys. Entering insert mode is as easy as typing 'i', while a programmer can return to normal mode with the 'esc' button.

Moving back and forth between insert and normal mode is non-trivial. It is much easier to skip around the document in normal mode than with insert. Navigation by word, line, and sentence is possible in normal mode, and normal mode provides access to ends of lines and beginnings of lines with a keystroke. Such navigation is not available during insert, so vim users train themselves to always go back to normal mode when not typing. Saving and exiting the file must also take place from normal mode.

Visual mode is useful for removing large blocks of text or changing indentations. Practically, most visual mode actions can take place in other modes, but visual mode allows for the visualization of selecting a block of code, so it is particularly useful in pair programming. Visual mode can be entered with 'v'.

Other modes include one where text can be manipulated from the command line, and a select mode, where characters are replaced as you type.

One downside of Vim is that learning all the necessary commands can be daunting. Fortunately, the vimtutor command provides a very good summation of the most important topics for learning Vim.

Saving a file from normal mode can be done with :w and leaving Vim requires :q. The two commands can be combined with :wq. Before the file is saved, it is stored in a swap file, which is convenient if something goes sideways.

Emacs

Emacs is a family of text editors, the most used one being GNU Emacs. Emacs was first released in 1976, making it one of the oldest open-sourced projects that is still maintained. It uses a separate environment than the standard terminal in which the other options discussed here open, making it more similar to VS Code, Atom, or Microsoft Word than its other UNIX-counterparts. Holding shift down while moving the cursor with the arrow keys will highlight the text, for example. There are also syntax coloring features that Vim could only imagine.

The other defining feature of Emacs is the frequent use of a control key to conduct operations. Ctrl + x is pretty much required before any major operation: saving, exiting, etc. Combined with the alt key, navigating through Emacs is also a two-key process. The advantages, compared to Vim, is that moving between modes is not required. Using the key combinations to move from one word or line to another or add tabs, there is no switching between modes to enter text.

While much easier to move around, Emacs can become quite congested if too many windows are open, but that is true of any editor. What really becomes congested is your RAM while running the program. Emacs is significantly larger of a program to run than the other options. The size of the help documentation is also significantly larger than Vim's, and the learning curve is a bit steeper.

Developers who swear by Emacs point to how it is highly customizable. Indeed, you can develop your own plugins for Emacs. And like Vim, there is a helpful tutorial for beginners.

Nano

Nano is by far the most beginner-friendly of the text editors discussed today. The top 12 key combination commands appear at the bottom of the program once opened with nano myFile.txt. Or better yet, one can open an empty file with a simple nano.

Nano has been around only since 2000, developed as a replacement for the Pico editor. Compared to the other two options, Nano comes with zero syntax highlighting capability. It also comes with some really cool search features that are lacking or difficult to access in other text editors. Somewhat limited in other advanced features, though, there is no real tutoring file because it is not needed. Commands descriptions are easily found from the always accessible get help menu. Saving is a simple ctrl + o; exiting just takes ctrl + x.

Commands that are now standard in text editors (ctrl + a as select-all; ctrl + c to cut to memory; ctrl + v to paste from memory) are available in Nano.

There really is not much more to say about Nano. Once one learns the more advanced Vim or Emacs, nano really does not stand out as a coding editing environment for much more than quick simple changes. But for someone editing in the terminal for the first time, Nano's short learning curve makes it a good entry vehicle to text editing.