Command-Line Productivity Hack - ctrl+x+e

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.

No. 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: ctrl-x e.

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 heartbeat to Microsoft Windows.

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 heartbeat with Microsoft Windows.

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.

Using ctrl+x+e with VIM to edit a command in the command line

Conclusion

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 these tutorials too...

Fix a Commit History With Git Interactive Rebase
Thu, Nov 28, 2019

Fix a Commit History With Git Interactive Rebase

Git interactive rebase is a powerful tool that can help you fix up your commit history to make it more meaningful, professional, and maintainable. In this post, I step through what it is, how it works, and when you should — and shouldn’t — use it.

How to Set Up PHP Debugging with PhpStorm, Xdebug, and PHPUnit
Sun, Nov 3, 2019

How to Set Up PHP Debugging with PhpStorm, Xdebug, and PHPUnit

Still using var_dump to debug your PHP code? Stop! While var_dump can be convenient, it’s a very blunt approach. In this article, I’ll show you how to set up proper debugging with PhpStorm, Xdebug, and PHPUnit, and give you a modern, sophisticated debugging experience.

Why Is My Website So Slow?!
Fri, Sep 27, 2019

Why Is My Website So Slow?!

Is your website (or web-based application) not performing like you expect it should? Not sure why or what to do about it? Then come learn about some key things you can do to have your website perform properly.


Want more tutorials like this?

If so, enter your email address in the field below and click subscribe.

You can unsubscribe at any time by clicking the link in the footer of the emails you'll receive. Here's my privacy policy, if you'd like to know more. I use Mailchimp to send emails. You can learn more about their privacy practices here.

Join the discussion

comments powered by Disqus