If you’re using Linux, at some point you’ll find yourself in the situation where you only have access to the terminal. In that case, you’ll want a text editor that highlights your syntax, helps you find typos in your code, and generally makes life easier. Here are our favorite scripting editors for Linux.
As CBT Nuggets trainer Shawn Powers explains in a recent Trainer Talk, Linux tries to use a text file every place you need to specify configuration settings and system information, rather than using specialized binary database files that requires particular tooling (hello, Windows registry). Source code, including scripts, are also text files.
So, it makes sense that Linux provides many options for editing text files. Several of them work fine when you can’t use a GUI — no menus, no scrollbars, no mouse or touch screen — and can even provide sophisticated capabilities in that limited environment. This can save you a lot of pain.
GNU Nano is a beginner-friendly editor that’s already installed in most Linux distros. It’s lean and intended for use in the terminal. In fact, it’s one Shawn recommends in his new Everything Linux course.
Nano’s learning curve is gentle, as long as you know your way around your keyboard. When you invoke Nano on a file, the file’s contents are displayed in your terminal and you can move around with the arrow keys and insert or modify text as you’d expect.
Nano is modeless, so all keystrokes, except keyboard shortcuts, go right into the file you’re editing. The bottom lines of the screen display the most commonly used keyboard shortcuts, including the key combination to get more help. Because the shortcuts are control-key and meta-key combinations, you do have to know where your control key and meta (alt or escape) key are.
For editing code files like scripts or config files, Nano provides auto-indentation, brace matching, and syntax highlighting that understands many languages and file types. You can also configure keyboard shortcuts and customize and extend syntax highlighting, via nanorc config files (text files, of course).
The flip side of beginner friendliness is that some tasks can’t be customized and some tasks are awkward in Nano. If you’re studying for LPIC-2, or have commensurate Linux experience, then you might opt for a more sophisticated editor. Nano doesn’t have the breadth of powerful (and complex) features of other editors — including the complex configurability — but it is great as a straightforward editor that lets you dig right in.
Vim is another popular editor. Vim’s precursor vi is part of the POSIX standard and the Single Unix Specification, so you can pretty much count on Vim or vi being available in your Linux distro. Its ubiquity and long life mean most system administrators know it, as well as many programmers. And because the line between those two job functions has blurred, it’s a good editor to use.
Vim is famously unconcerned about beginner friendliness. The first-time user confronts a display of the file’s contents — or, if you’re creating a new file, a largely blank screen — and no indication of what to do next, including no indication how to get help (spoiler: type “:help<enter>”). So, before you can do anything, you must get help in some fashion, and learn the basic commands.
But when your fingers know the commands, they need never leave the keyboard, and you can rapidly accomplish magic.
Vim has multiple modes – normal (navigation and text manipulation), insertion (add new text), command-line, and several more. The same keystrokes have radically different effects depending on the current mode.
Vim has a full range of support for editing source code – syntax highlighting, brace matching, auto-indentation, code completion, code folding, compiler integration, and more. But note that your pre-installed Vim may be the vim-tiny package. If so, for advanced features like support for programming languages, you’ll need to upgrade it to full Vim.
Vim is highly configurable, but configuring Vim is itself a deep topic. Vim has its own scripting language. Plugins (extensions) are available online, as well as articles describing how to configure Vim with settings and plugins to produce a sophisticated environment for a particular language. You can extend and tweak your Vim environment to your heart’s content.
Emacs is a powerful extensible editor that’s in many Linux distros and can be installed in most other Linux environments. GNU Emacs was the first product released by project GNU. Like vi/Vim, Emacs has been around a long time, and like vi/Vim its core user interface feels like a throwback to an earlier era.
Emacs makes a bit of an effort to be beginner friendly. But there’s at least as large of a learning curve as Vim, and until you learn the basic commands, it will be frustrating. Emacs in the terminal does have a menu bar, at least. When you invoke Emacs without specifying a file to open, the initial screen provides links to get help, to access the built-in tutorial, and so on. It also explains what control and meta mean.
Emacs is more an environment than an editor. It’s extremely extensible and contains a Turing complete Lisp interpreter. It has its own ecosystem of packages, and has been integrated into many internet services; an Emacs installation usually includes built-in email, news, outlining, command shell, calendaring, debugger, version control systems, games, and other things. There’s a kitchen sink in there, somewhere.
Emacs aficionados famously can spend all day inside it, never needing to switch to a different app. That’s good because Emacs is not lean. If you are working on a very small Linux box, you’ll notice that there’s a lot to load at startup.
Emacs has a large toolbox of sophisticated support for editing source code, right out of the box. Check “info mode” (control-h i) for details. There are also many articles online about people’s custom setups; you can download and add packages and options to turn it into a deep IDE for most languages. You can extend and tweak your Emacs environment even more than Vim.
But, once again, if you’re tackling the entry-level Linux Essentials course, you might not want to start with GNU Emacs.
Beyond the Terminal
Text-mode Vim and Emacs both live happily in a terminal, but both also have GUI modes that make full use of the capabilities of a modern display and pointing options. So the benefits of learning Vim or Emacs is not limited to those times you’re confined to a terminal. Though when you have a more capable display, there are also other options to consider, like Sublime Text and Atom.
For those times you’re limited to a terminal, Linux provides several capable options to make your life easier. Once you’ve explored a couple, you’ll cope like a champ in the terminal just like in the GUI world, and you’ll be ready to join in the editor wars like an old hand.