Editing text at the command line with micro
Small and Simple
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.
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).
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
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.