Editing text at the command line with micro

Small and Simple

Article from Issue 248/2021

Editing text at the command line doesn't have to be daunting. Micro brings the ease and intuitiveness of a graphical editor to the Linux terminal.

Linux users are spoiled for choice when it comes to many types of software. That's especially true for text editors. When I first started writing this article, I tried to count as many editors as I could just off the top of my head. I stopped when I got to around 32.

Quite a few of those editors run at the command line. While I've used several, I've never had great relationships with command-line text editors. I'm not sure why that is. Maybe it's just we don't have enough in common with each other to form a strong bond. Recently, though, I was working with a command-line application that played better with terminal text editors than with graphical ones. So, I duly set my default editor to the venerable GNU nano editor, which was the only terminal editor installed on my computer. While I've used nano in the past, I was quickly reminded that it isn't for me.

Instead of using software I don't particularly like, I searched around for an alternative and came across micro [1]. Billed as "a modern and intuitive terminal-based text editor," micro turned out to be great substitute for nano. In this article, I look at how any Linux user, regardless of their level of comfort with the command line, can start using micro and configure it to meet their needs.

Setting Up

There are several ways you can install micro. The easiest of those is to install it using your Linux distribution's package manager. If micro isn't available in your package manager, run this command in a terminal window to download a prebuilt binary:

curl https://getmic.ro | bash

From there, move the file (conveniently named micro) to a folder in your path.

Another option is to install micro as a snap package by running this command in the terminal:

snap install micro --classic

If compiling software is your thing, you can download micro's source code from its repository on GitHub [2]. The editor is written in the Go programming language. You'll need Go v1.11 installed on your computer, and you must enable Go modules as well.

Start a New File

So micro is on your computer. Now what? Get going by opening a terminal window and typing micro or micro <name of file to edit>. Figure 1 shows micro editing a new, empty file.

Figure 1: A new and empty file, started in micro.

From there, start typing – nothing complex or out of the ordinary for any text editor, whether on the desktop or at the command line.

Micro uses many (if not all) of the same keyboard shortcuts that you're familiar with from using desktop applications – although the notation in the help section may differ slightly. For example, if you're used to seeing Ctrl+X, note that Ctrl-x is just another way to write the same key combination.

Copy text by highlighting it and pressing Ctrl+C. Paste that text by pressing Ctrl+V. Or press Ctrl+O to open a file and Ctrl+S to save it.

Press Ctrl+E and then type help defaultkeys to display a list of micro's keyboard shortcuts.

You can also use your mouse to select and highlight text. There's no right-click support (as you'd find in a desktop application), but pressing the scroll wheel on your mouse pastes whatever is in your clipboard into your file.

Using the Command Bar

I've already mentioned the Ctrl+E shortcut. When you press that combination of keys, the editor's command bar displays at the bottom of the screen. In the command bar, you can type commands like replaceall to find and replace all instances of a word or phrase, set softwrap true to turn on word wrapping, or help commands to get a list of all of micro's commands.

If you only remember part of the name of a command, type it and press the Tab key to complete it. If there are two or more possible completions, micro displays them and you can press the Tab key again to choose one (Figure 2).

Figure 2: Tab completion can help you find a command.

For example, when you press Ctrl+O to open a file, you type the name of the file and, if it's in another directory, the path to that file on the command bar. Press the Tab key to complete the names of the directory and of the file.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95