You know the situation: You are halfway through typing a long command (for example a commit message) and realize that you have forgotten to execute some prerequisite command that can not be added with &&
. Normally when that happens to me, I select what I have typed with the mouse, copy it to the clipboard, press Ctrl-U to clear the line, run my prerequisite command and paste form the clipboard. But maybe there is a better way, preferably without needing to use the mouse? I'm looking for solutions for bash and/or zsh.
Bash – Keyboard shortcut to store typed command and clean the line
bashcommand-line-interfacezsh
Related Topic
- Windows – Does Windows have a built-in ZIP command for the command line
- Windows – What’s the command-line utility in Windows to do a reverse DNS look-up
- Bash – the difference between double and single square brackets in bash
- Linux command line best practices and tips
- Bash – Clean way to write complex multi-line string to a variable
- Linux – Find out symbolic link target via command line
Best Answer
After you've used CTRL-U you can use CTRL-Y to paste back what you've erased. It works after erasing a word or a number of words with CTRL-W too.
Note this way you don't really need to copy anything to the clipboard or select it with the mouse - CTRL-U actually yanks the line to a separate clipboard, so to speak.