Editing Text at the Command Line with Micro
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 seemed to play better with terminal text editors than with graphical ones. So, I duly set my default editor to the venerable GNU nano editor. Why nano? It's 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 something similar and came across Micro. Billed as a modern and intuitive terminal-based text editor, it sounded like a good substitute for nano. Here's what I discovered.
There are several ways you can install Micro. The easiest is to use your distribution's package manager. You can also grab a binary package or run this command to download the executable:
curl https://getmic.ro | bash
Another option is to install a snap. I know that more than a few people don't like snaps. If you're one of them, and want to have a go at me for mentioning the snap package, don't bother. I'm not interested.
Get going by opening a terminal window and typing micro or micro followed by the name of the file that you want to edit.
From there, start typing. Nothing complex or out of the ordinary for any text editor.
Micro uses many (if not all) of the same keyboard shortcuts that you're familiar with from using desktop applications. For example, copy text by highlighting it and pressing CTRL-c. Paste text by pressing CTRL-v. Or press CTRL-o to open a file and CTRL-s to save it. Pressing CTRL-e and then typing help defaultkeys displays 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
A couple of paragraphs back, I 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:
- open [filename] to open a file
- replaceall to find and replace all instances of a word or phrase
- set softwrap true to turn on word wrapping
- help commands to get a list of all of Micro's commands, which you can also find here
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 Tab again to choose one.
A few paragraphs ago, I mentioned that you can press CTRL-o to open a file. When you do that, you type the name of the file and, if it's in another directory, the path to that file on the command bar. Again, you can press the Tab key to complete the names of the directory and the file.
A nifty feature of Micro is the ability to have multiple files open at the same time. If you have one file open in Micro, you can open another one in a tab by pressing CTRL-e and then typing tab followed by the path to that file.
The idea is more or less like the tabs you find in a graphical editor. The tabs you're working with are listed at the top of the editor:
You can switch between tabs by pressing CTRL-e and then typing tabswitch followed by the number of the tab (the one on the left is tab 1, and the numbers increment as you move right). Or, you can click on a tab with your mouse. I prefer doing the latter, to be honest.
One of Micro's selling points is that you can configure it to make the editor work the way that you want it to. The quickest way to do that is to open the file settings.json under the .config/micro folder in your /home directory.
That file stores configuration information in a format called JSON. Don't let that intimidate you. JSON uses what's called attribute/value pairs to store information. With Micro's settings.json file, the attribute is a configuration option and the value is often either true or false. Sometimes, it's a number or something else specific to an option.
Here's what my (rather sparse) settings file looks like:
You can find out more about Micro's options by reading this reference.
Plugins expand Micro's abilities. There are 20+ plugins that you can add to the editor. Most of them are a bit techie for my tastes. The ones I've found most useful, in case you're wondering, are the spelling checker and word count plugins.
Here's the spelling check plugin in action:
Install a plugin by pressing CTRL-e to open the command bar, then typing plugin install [name of plugin].
Is That Everything?
Definitely not. You can also change Micro's keybindings and colours. You can also split the screen you're working with either horizontally or vertically, or run a terminal command from within Micro. And a lot more.
Micro comes with a nice set of features, but also wraps those features in a small package. That makes Micro one of the fastest and easiest-to-use command line text editors that I've test driven.
Micro lives up to its billing as an intuitive terminal-based text editor, which is why I'm keeping it around for those times when I need to edit text files at the command line.