Get yourself a good terminal text editor
I think that everyone deserves a good terminal text editor. Knowing how to do some efficient text editing on the command line is useful even for people who don’t “live” in the terminal. At the very least, you will probably need to edit some scripts or configuration files quickly. Maybe even process some text output interactively. So where to start?
The first step is to pick and install a powerful text editor. I recommend using a modal editor with advanced editing features. Learning the basics is not too difficult, and the little tips and tricks you can acquire along the way will get you to places where simpler text editors can’t.
Neovim is all the rage now as a modern alternative to the famous Vim (and yes, it is good). My recommendation, however, goes to Helix. On the text editing side, the editors are comparable, but Helix gives you a lot of other functionality out of the box with almost zero configuration, so most things (opening a file from a file picker with fuzzy search, autocomplete support, syntax highlighting, Git gutters, …) just work right away. No plugins, no weeks of tweeking the config, just an editor that makes you productive right away.
The second reason why I’d recommend Helix to newish command line users as opposed to Neovim is that the commands are discoverable. Getting some form of help or aid directly in the editor when performing operations is just fantastic, and more programs should do that.
The third reason is that the modal editing favors selection first approach rather than action first approach known from Vim. It makes operations more natural, because in traditional desktop editor we also do selections first and then perform actions on them.
The second step is to set your favorite editor as default in the shell. That can be done by exporting EDITOR
variable in the shell’s startup configuration file, e.g. in .zshrc for Z shell like this:
# set Helix as the default editor
export EDITOR="hx"
This is powerful because now, when other applications want you to edit a file, the file will open in the configured editor. Command line applications like Git also prompt users for text operations in the chosen editor so that you can use Helix, Vim, or another editor to write commit messages or perform interactive rebasing.
But that’s not all. We can sometimes optionally “drop into” the default editor to edit text on the command line. Consider two practical examples:
The command line text itself (commands that we type) can be edited in the default editor, typically by pressing Ctrl+X Ctrl+E in the shell, at least in Bash and Zsh.
Psql command line utility for PostgreSQL can switch the input to write and edit SQL in the default editor with
\e
The ability to use a proper text editor for such situations can come in handy to deal with long inputs, to get syntax highlighting, to find and replace quickly, and so on.
As you can see, picking and installing a good terminal text editor will pay dividends since it can become ubiquitus text manipulation tool. Even though editors like Vim and Helix have steeper learning curve, they really help in being more productive in the terminal.
— Petr