Good evening, folks!
The other day, I issued a long command in bash, and it turned out it was wrong, I needed to replace all 20 commas with spaces. Editing the line manually is not an option, it was too long. Moreover, I knew there was a hotkey to edit last command in an editor, but forgot it. Searching for a while I bumped into this article (http://www.vim-fu.com/editing-a-long-bash-command-using-vim/), which reminded me that the combination is
Ctrl-X, Ctrl-E by default.
However, the comments to the article added some useful information. There is an utility called
fc, which does the same and even more, it can push not only the latest command into an editor,
vim in my case. That’s nice, but what if I decided not to issue the command after editing? The same comments moved me to learn a vim’s command I didn’t know about. It’s
:cq, which doesn’t save the file and exits with an error code.
Ctrl-X, Ctrl-E — combination to edit the latest command in an editor. Works in bash and zsh.
fc — tool that does the same.
:cq — vim’s command to exit with an error code. Use it not to run the edited command.
Never stop learning!