Senin, 25 Mei 2020

nano vs. Vim: The Best Terminal Text Editors, Compared

linux-terminal-shutdown

You may be surprised to learn that many aspects of your Linux desktop are not hidden behind complex code. Numerous programs and system settings are tucked away in text files.

You can open these with your default text editor such as Gedit or Kate, but the terminal is often faster, especially when you need administrator permissions.

For terminal-based text editing, two of the top choices are GNU nano and Vim. Which is better? I’m not going to wade into that question, but there are core differences that set these two text editors apart.

A Brief History of GNU nano and Vim

The GNU nano (more commonly referred to as “nano”) project was created in 1999 in order to emulate and improve upon the Pico text editor. Developers claimed GNU nano to be 2/3 to 1/8 the size of the Pico binary, which made it very lean and usable on even the weakest systems.

Vim, originally developed in 1991, is based on the original Vi text editor that was developed in 1976. Like GNU nano, Vim began as an effort to improve an earlier project.

GNU nano

Nano Linux terminal text editor

GNU nano has a reputation for being relatively user-friendly. If you’ve never used nano before, there’s a good chance you can fumble your way through without help.

To get started, you can open or create a file by typing:

nano /home/user/HelloWorld.txt

This will show you a recognizable user interface. The title of your text file appears at the top and the text contained within the file appears in the middle. The actions you can perform line the bottom. You complete these actions by pressing Ctrl plus the indicated key.

For example, you exit and save a file using Ctrl + X. Admittedly, I was very concerned about how to save my file the first time I used nano, as the text editor only lists this command as “Exit”. But when you try to edit, Nano asks if you want to save.

As the bottom of the screen shows, nano contains much of the functionality you would expect from a graphical application. You can cut and paste, find and replace words, and much more.

GNU nano’s features include:

  • Autoconf support
  • Goto-line# command w/o flag
  • Case sensitive search function
  • Interactive search and replace
  • Slang and ncurses support
  • Autoindent ability
  • Displayed tab width option
  • Regular expression search and replace
  • Toggles for cmdline flags via meta keys
  • Tab completion when reading/writing files
  • Soft text wrapping (text doesn’t wrap as in full-fledged document editors, with continuations indicated with $)

Overall, nano is a great option for newcomers to terminal text editing. You can get to try your hand at opening files from the command line and navigating using primarily a keyboard without having to throw out much of what you know about text editors.

On a DEB-based system such as Debian or Ubuntu, you can install GNU nano using:

sudo apt install nano

On Fedora, a RPM-based system, you can install using:

sudo dnf install nano

Since nano is a command-line program you likely won’t find it in GNOME Software or alternative Linux app stores. But you can install it using traditional package managers, such as Synaptic.

Vim

Vim Linux terminal text editor

Vim, by contrast, isn’t quite so welcoming to newcomers. When you open a text file you see just the contents of the file and no indication of how to use Vim itself.

Getting started is straightforward though. You open a file using the following command:

vim /home/user/HelloWorld.txt

At this point, you’re left having to read the documentation, search online, or mash buttons and hope for the best. If you do opt for the last option, there are some safeguards in place. You can’t do any real editing without pressing I to enter “Insert” mode. After you’ve made your edits, you then press Esc to exit the mode (at least you could probably guess that).

To perform other functions, when not in Insert mode, press the : (colon) key. Then type the key or keys that correspond with what you want to do and press Enter.

For example, to save the changes you’ve made to your text file, type :w and hit Enter. This will “write” changes to your file. See, the w is intuitive when you think in terms of read and write rather than open and save.

When you’re done, you can then type :q and hit Enter to quit the program. Again, rather intuitive.

Once you learn the behavior, there’s a certain beauty to Vim’s minimal aesthetic. You don’t have clutter floating inside your terminal window. All you see on screen is the text inside your text file. If you’re comfortable with typing (and you very well may be, considering you’re in the command line), Vim’s interface can feel rather natural.

There’s another reason to make the effort. Vim has the advantage of being more powerful than GNU nano. Not only does Vim contain more features from the get-go, you can also customize the program with plugins and scripts.

Vim’s features include:

  • Automatic commands
  • Completion commands
  • Digraph input
  • Higher memory limits than vanilla vi
  • Split screen
  • Session recovery
  • Tab expansion
  • Tag system
  • Syntax coloring

After you’ve taken the time to add in your desired plugins, Vim becomes a capable alternative to full-featured graphical text editors such as Sublime Text or Visual Studio Code. If you’re not into coding, that doesn’t mean it’s time to give Vim a pass. With a markdown plugin available, Vim is also a capable option for writers.

Is Vim harder to grasp than nano? For sure. But with the ability to add features from other text editors, you can really make Vim your own.

On Debian or Ubuntu, you can install Vim using:

sudo apt install vim

On Fedora, use:

sudo dnf install vim

GNU nano vs. Vim: Which Do You Prefer?

If you can live with with a steeper learning curve, then you may find yourself falling in love with Vim. It’s simple and rather attractive in its own way.

But if you want an option that’s straightforward and gets the job done, there’s little reason not to pick GNU nano. It doesn’t have the mystery that Vim has. You don’t have to read a manual to use the program, which in general is a hallmark of good design.

At the end of the day, both are equally capable of editing the same text files. And when you find yourself falling in love with either program, here are ways to integrate plain text files into how you use your computer.

Read the full article: nano vs. Vim: The Best Terminal Text Editors, Compared

Tidak ada komentar:

Posting Komentar