Emacs, Nano, or Vim: Choose your Terminal-Based Text Editor Wisely

Emacs, Nano, or Vim: Choose your Terminal-Based Text Editor Wisely

Image for post

The opinions expressed herein are not representative of Linode, its staff, or even the author on some days. All attempts at Internet argument will be responded to with baby animal gifs without regard for context.

You?ve provisioned a Linode and booted it up with a cool-sounding distro. You?ve read the Introduction to Linux Concepts and Getting Started guides, and now you?re ready to set your hostname. Go ahead and edit /etc/hosts.

Should you use Vim or Emacs? Is it okay to use Nano? What?s Neovim? Or should you use another text editor entirely?

Emacs versus Vim is a conversation known to strain relationships, but we?ll try to break down some of the differences and steer you in the right direction without losing too many of your developer friends.

Nano

Nano is the built-in basic text editor for many popular distros. It?s usually already contained in the distro, doesn?t take any learning or getting used to, and all its commands and prompts are displayed at the bottom.

Use Nano if:

You?re new to the terminal, or you just need to get into a file for a quick change. Compared to more advanced editors in the hands of someone who knows what they?re doing, some tasks are cumbersome and non-customizable. But if you?re not spending the day in a terminal-based text editor, you?re probably fine with Nano. Don?t let anyone bother you, use it with pride.

How to Nano:

From your terminal, enter `nano` and the filename you want to edit.

If the file doesn?t already exist, it will once you save it. Commands are listed across the bottom and are triggered with the Control (CTRL) key. For example, to find something in your file, hold CTRL and press W, tell it what you?re searching for, and press Enter. Press CTRL+X to exit, then follow the prompts at the bottom of the screen.

Emacs and Vi

According to Slate, Emacs and Vi are ?Among the longest-lived applications of all time.? The Wikipedia entry on the differences between Emacs and Vi describes the Holy War between the two applications which has raged since the late-1970s.

Both editors require learning their respective commands, which means you won?t be able to open them and get right to work. But expert users of either seem to make their editor of choice perform magic, often without even leaving their keyboard?s home row.

Don?t start out feeling like you need to be an expert right away. I?ll walk you through getting started and once you?ve settled into basic use and committed to an editor, you?ll gain mastery through use.

Emacs

Emacs has been in development since 1976. That?s a lot of time to develop such necessary plugins as Helm, Autocomplete, and Org-mode. Emacs has so many available features like a terminal, calculator, calendar, email client, web browser, and Tetris, it?s often spoken of as an operating system itself.

I found that starting Emacs was relatively simple, but the more I learn, the more there is to learn. Thanks to ?buffers,? those plugins, and the way Emacs treats ?windows,? it?s the editor you might use if you spend all day in an editor and don?t want to be inconvenienced or distracted by having to switch applications.

That?s not to say Vi and its derivatives aren?t for all-day use, but the multiple sessions and kitchen-sink-style expandability of Emacs seem to be part of the main draw for its devotees.

Emacs commands are accessed through keyboard combinations of CTRL or ALT and another keystroke. When you see shortcuts that read C-h or M-x, C stands for the control key and M stands for the Alt key (or Escape, depending on your system).

How to Emacs:

Enter `emacs` in your terminal, and access the built-in tutorial with C-h t. That means, while holding CTRL, press H, then T.

Or, try key combination C-h r to open the manual within Emacs. You can also use the manual as a playground; just remember to quit without saving by pressing key combination C-x C-c.

Helpful Emacs links:

  • Emacs wiki
  • GNU Guided Tour
  • Cornell Emacs Quick Reference

Vi/Vim

Vi or one of its variants typically comes with your distro-of-choice. It?s considered a ?modal? editor, which means there are different modes for navigating files and editing text. Because you navigate Vi most efficiently through the use of keyboard commands and shortcuts, Vi is better experienced than explained.

When you enter Vi, you begin in normal mode and navigate using keyboard commands and the H, J, K, and L keys to move left, down, up, and right, respectively.

Using Vi is more like problem solving with a healthy dash of talking to your computer. Consider it a meditation; for best results, practice stating your intentions. For example, while in normal mode, to delete a word, press D, then W. To change everything inside of a parenthesis, place the cursor inside the open parenthesis (, then press c, then i, then open parenthesis (.

You might have some initial trouble navigating Vi if you?re using a Dvorak keyboard, but if that?s the case, it?s likely you knew that already.

How to Vi or Vim:

Enter `vi` or `vim` in your terminal.

On many distros, chances are, even if you enter `vi` into a terminal, you?re actually opening Vim. Vim is a vi successor with some improvements. It runs by default on OS X and some Linux distributions when `vi` is run.

To exit Vim without saving, press ESC to enter normal mode, then press : (colon) to access the command line (a prompt appears at the very bottom) and enter q!.

The : (colon) operator begins many commands like :help for help, or :w to save. To save and quit, you could use that prompt and the key combination :wq, or hold down SHIFT and press Z two times (the shortcut SHIFT+ZZ).

If you?re stuck at the prompt and don?t remember the operator you want to use, enter : (colon), then press CTRL+D for a list of possibilities.

Try Vim:

To learn Vim basics, enter `vimtutor` in your terminal to access an interactive walkthrough.

When you?re ready for some advanced practice, try VimGolf for exercises that encourage finding better, more efficient solutions to solve challenges.

I like displaying line numbers. The command, `:set number`, makes it easier to jump to specific line numbers quickly. For example, to jump to line 16, type in :16 (colon 16)

Like Emacs, there are many plugins available for Vim. Check out VimAwesome for plugins to help with whatever you?re working on.

Helpful links:

  • Swathmore?s Tips and Tricks
  • Linux Academy?s Vim Reference Guide
  • VimGolf

Also try: Neovim

Self-touted as ?literally the future of Vim,? Neovim has been gaining traction as the ?drop-in replacement for Vim? it aims to be. Neovim is an effort to refactor (basically, rewriting the insides to work better without messing up the outside) Vim?s codebase and bring various optimization features, like asynchronous plugins (they run separately, as needed), a terminal, and general improvements. Be aware though, while reviews have been generally positive, Neovim is currently in alpha.

How to Install Neovim:

Install the app using your package manager of choice, then enter `nvim`. Treat it like Vim as described above and check out the Neovim documentation.

But what if I like immersing myself in Emacs and wish it acted more like Vim?

Emacs Evil mode might be for you. It?s not Evil because it?s more difficult (no more than usual); no, evil mode makes Emacs act a little more like vim by giving it modes and enabling commands accessible via the : trigger (colon trigger) command.

Honorable Mentions

Ed

Ed has been there since the dawn of Unix, and can be invoked with a simple `ed` followed by a file name. The first thing you?ll notice is that nothing seems to happen. That?s because ed is so lightweight (under 100kB), that it exists right in the terminal lines.

Like Vim, ed is modal, and has a visual mode a little different from what you might be expecting. Use it if everything else is broken or if it?s 1991. If you?re determined to learn ed, check out the GNU ed Manual.

If you?re just opening it to poke around, enter `Q` to quit without further prompting.

gedit

Same use case as nano, but rather than being terminal-based, gedit requires a graphical user interface (GUI). Because of this, it doesn?t really belong on a list of terminal-based text editors, except to say that it?s an option on some systems. Use it if it makes you happy.

Wordstar 4.0

Editor-of-choice for killing off your favorite characters.

Wordperfect

Editor-of-choice for the aging law firm. Like Vim and Emacs, WordPerfect has been around since the late 1970s, and was embraced by law firms in the DOS days of the early ?80s. If it?s your editor-of-choice, when you apologize to your friends for sending weird files, remind them that OpenOffice and LibreOffice will open pretty much anything on most graphic-based operating systems.

It boils down to this

Try an editor and its tutorial, watch a few videos of people using it for your intended purpose, then spend a day or two using it with real files. One of the nice things about fundamentalist Vim and Emacs users is that both have littered the Internet (yes, capital ?I?) with tips, plugins, shortcuts, games, and bible verses on more efficient use for every possible use case.

The best editor for you is the one that makes you feel like you?re getting things done; not necessarily the one you?ve sunk the most time into. Although, once your fingers are trained and you?ve got things configured the way you want, you?re probably unlikely to switch.

Share your text editor adventures, favorite tips and plugins, feelings, follies and deepest secrets in the comments.

Up next, hard tabs or soft tabs?

13

No Responses

Write a response