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
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.