Technology / System Admin

VI vs Nano: Which is the Best Text Editor

VI vs Nano: Which is the Best Text Editor picture: A
Follow us
Published on July 19, 2021

Have you ever wondered which text editor is the best one to use in Linux?  One of the best things about the world of Linux is the plethora of ways to get jobs done. That includes programming and editing configuration files in the command line. Depending on who you ask, Linux aficionados might tell you to use Emacs, Vi/Vim, or Nano. It is a fiercely debated topic.

Emacs and Vi/Vim are complex and powerful text editors while Nano is a lightweight, simplified editor. While it's fun to have light-hearted debates about which command-line text editor is the best text editor to use, at the end of the day they are truly nothing more than different tools. So, let us take a look at Vi vs Nano and discuss which one is better.

For this post, we are only going to look at Vi instead of both Emacs and Vi. That's because they both share the same philosophy of being very customizable and powerful text editors.  Likewise, Vi and Vim are essentially the same application, so for simplicity, we are going to be referring to Vi.

A Brief Background Of Vi and Nano

Both Vi and Nano are wildly different applications with different philosophies. Before you can fully understand why you should use one text editor over the other, you should understand why each application was developed and where its roots lay.

The History of Vi

Vi has a long history.  It was originally developed as an application called Ex in 1976 for the Unix operating system.  Ex was originally developed as a simpler solution to the Ed command-line editor.  It wasn't until 1978 with the release of version 2.0 that Ex was renamed to Vi. At that time, many people had considered Vi to be a resource-intensive application for computer hardware, but Vi has persisted to become one of the most popular command-line text editors in Linux.

Though people commonly refer to Vi as a singular application, it is in fact many different applications.  Vi has been forked numerous times.  Some versions still contain some of the original source code dating back to 1976 while others are complete re-writes that include compatible layers to the original code.  Likewise, Vi comes in both proprietary, licensed versions as well as open-source versions.  Different Linux distributions will contain different versions of Vi though they all largely look and operate the same way.

The History of Nano

Nano was originally developed in 1999 (long after Vi) under the name TIP (Tip Isn't Pico). Its goal was to emulate the Pico text editor (part of the Pine email client) but with additional features. TIP was renamed to Nano in 2000 to avoid naming conflicts with another existing Unix utility with the same name. In February of 2001, Nano became part of the GNU project and is now commonly known as GNU Nano. Nano was developed strictly as a more feature-rich version of Pico.

How Do Vi and Nano Work?

Now that you have a basic idea of where each text editor developed from, let's explain how both Vi and Nano work at a higher level.

How Do You Use Vi?

As we mentioned above, Vi was created as a full-featured text editor for the Unix operating system in the late 70s.  At that time, graphical interfaces were computationally very expensive and not common practice. Interactions with computer systems were performed through a terminal command-line environment. So, computer operators needed a tool that could handle every aspect of text editing from editing configuration files, to writing text documents, and a full computer programming environment. This is the reason why Vi is so feature-rich. It needed to handle an awful lot of tasks.

Vi has two different operating modes:

  • Insert Mode

  • Command Mode

Insert mode is used to edit and create text documents.  We use the term 'text document' loosely here.  These could be configuration files, programming files, or word documents.

Command mode is how operations are performed in Vi.  Command mode is used for things like saving documents, quitting Vi, opening documents, copying and pasting, etc…

The ESC key is used to switch to Command mode while the 'I' key is used to switch to Insert mode. While in insert mode, documents are navigated with the arrow keys on a keyboard.  Any text inserted into a document is added to that document buffer.

Commands are typed into Command mode to perform operations.  Unlike keyboard shortcuts that would be used in most applications, commands are manually typed into Vi.  For instance, to save a document, you would type ':w' in command mode and press enter to submit that command.

Commands can be stacked. For instance, to save and quit Vi, type ':wq' into Command mode. Note that the 'w' command is inserted before the 'q' command.  Vi performs operations in the order that commands are added. Because Vi is so powerful, essentially each key on a keyboard represents a command.

Here is a list of common commands for Vi:

Save and continue

:w

Save and Exit

:wq

Quit

:q

Copy

yy

Paste

p

New Line

0

Go to the last line

G

Navigate to a specific line

XG

One of the reasons that Vi has enjoyed such longevity is its plugin system.  Vi can be adapted for any use. For instance, vim-rainbow is a plugin that helps to identify opening and closing brackets in a programming environment — not something that Vi can do natively but a function that programmers need.

How Do You Use Nano?

Nano's philosophy is different from Vi's. Because Nano was created to supersede Pico, its goal was to be efficient and lightweight. By the time Nano was created, computer systems, including Linux, had complex and robust graphical interfaces.  The interaction paradigm with computers had drastically shifted by this time. So, instead of typing in commands to perform operations in Nano, it uses keyboard combinations instead.

For instance, Nano doesn't include multiple modes.  Instead, both editing and operations are all performed under the same instance in Nano. Nano doesn't have a concept of modes. Saving and quitting a document is as simple as pressing Control+X on your keyboard. If you want to search for a specific word in Nano, press Control+W on your keyboard.

Nano is gracious enough to include a cheat sheet at the bottom of its editor window.  This cheat sheet lists the most commonly used keyboard shortcuts used with Nano.  It is dynamic, though, so depending on which command you are using in Nano, that cheat sheet will display different suggestions.

Here is a list of the most common keyboard shortcuts for Nano:

Save and Close

Control+X

Save and Continue

Control+O

Search

Control+W

Skip to Line

Control+_

Cut

Control+K

Paste

Control+U

Should You Use Vi or Nano?

As we mentioned above, debating the Vi versus. Nano topic is almost a religious argument.  Depending on who you ask, you will get a different answer with different reasoning. I prefer Nano, but that preference very much goes against the normal opinion.  So, let me explain both points of view.

Why Should You Use Vi?

Vi is a long-standing tradition in the Linux world.  It's a proven text editor with more than 30+ years of development. If you need a one-stop-shop in the command-line to write and edit documents — from configuration files to programming or basic document creation — you can do it all in Vi.  Because Vi has a plugin system, it's very extensible, too, though plugins need to be installed, configured, and maintained separately from Vi.

Once you understand how Vi works, how to recognize which mode you are in, and know what commands to use, it's not a hard application to run. Learning to use Vi does take a bit of practice, though.

Why Should You Use Nano?

Nano is often described as a great command-line editor for beginners. That's because it is very straightforward and easy to use. I wouldn't let that "beginners" label hold any weight, though.

Vi was a great utility back in the '70s, '80s, and '90s, but the interaction paradigm with computer systems has long since changed. That doesn't negate the fact that you need a command-line editor for Linux, though, especially with server administration. Sometimes you are required to hop into the command line to fix or configure things in Linux.

The reason I prefer Nano is that it is lightweight and quick to use. When I'm configuring or fixing things in Linux, I want to be able to hop into a configuration file, update what I need to, and then move on. Though Vi can be easy to use once you learn it, Vi still requires overhead to use.

Where Vi shines over Nano is its versatility to be used for so many things.  I'd prefer to use more modern tools for those jobs, though.  For instance, if I am programming an application or writing a script, I would much rather use a purpose-built IDE or code editor, like Visual Studio Code or Atom, with an extensible and simple graphical user interface.  Despite the plugins that Vi has access to, programming in a code editor with a modern interface is far easier.

Today, there are tons of applications that can perform the functions of Vi in a much faster, more intuitive way, but as I said, sometimes you still need to edit documents in the command-line in Linux.  It's the nature of the beast, and for that, I'd prefer to use something quick and easy. Nano is my go-to command-line text editor for that reason.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522