Command-Line Productivity Hack - ctrl+x+e
There are lots of tips, tricks, and ideas around for hacking your command-line productivity to make you more efficient. However, in this post, I’m not going to show you something that’s super in-depth, ultra-detailed, or talk about an app that you have to install, ctrl+x+e.
There are lots of tips, tricks, and ideas around for hacking your command-line productivity to make you more efficient. However, in this post, I’m not going to show you something that’s super in-depth, ultra-detailed, or talk about an app that you have to install: ctrl+x+e.
In this post, I’m going to show you an existing feature of your Linux/macOS shell, one that has existed for quite some time.
It’s a small key sequence:
What’s this do?
It takes the existing command that you currently have on your command line and opens it in your shell’s editor (which is defined by the
$EDITOR environment variable).
This could be any editor; an older one, such as VIM, Emacs, Nano, Pico, or Ed, or a more modern one, such as Gedit or LeafPad.
Yep. That’s it! Tiny hey? Well, I did promise you something small. And it’s hard to get much smaller than this. But seriously, I digress. This is a keyboard shortcut that I use almost every day, whether I’m maintaining code or technical documentation. This is because it’s far easier to edit the text in an editor (says the VIM lover) than on the command line.
Now, I know that there are ways to augment the command-line so that it’s a lot more potent than it is by default. However, if you already have stacks of muscle-memory around one, or several, editors, why learn yet another set? Why not make use of what you already know?
A Small Example
Now, let’s step through a small example. Let’s say that you have the command below open in your command line (with or without the line breaks).
And let’s say that you want to remove the trailing
--color argument, and change the search string from
grep -rin 'heartbeat' \ ./modules/*_manual/ \ --color=always \ --include="*.adoc" \ --color="always"
Sure, you could move to the end of the command, which will take a little bit of time and use esc+backspace a few times (or just backspace/delete) to delete the trailing
--color argument, then the up arrow a few times (or jump to the start) and replace
That’s a lot of keystrokes and quite some fiddling around. Depending on the quality of your favourite text editor, you could do this a lot faster. Using VIM as an example, I can make the change by:
- Move to the end of the line and select back to the third last double-quote in the line and delete that selection.
- Navigate to
hear, select the word, and replace it.
That’s far more efficient — and less finicky). How does that sound to you? A decent productivity hack for your command-line of choice?
If you’ve never used it before, it might not seem so, and it may take a bit of getting used to. However, give it a chance, and I’m pretty sure that you’ll find it’s a decent performance boost.
If you’d like to see it in action, check out the demo I made below.
And that’s a small, yet handy, productivity hack that will help make you loads more efficient when using the command line. I’d love to get your feedback on it. Would you use it? Do you use it? What do you think of it?
You might also be interested in...
- Fix a Commit History With Git Interactive Rebase
- How Docker Simplifies Creating a Multi-distribution Linux Shell Script
- How to Set Up PHP Debugging with PhpStorm, Xdebug, and PHPUnit
- Why Is My Website So Slow?!
- Don't Write Code When You Don't Have To
comments powered by Disqus