Vi mode solution
Keyboard-only solution. All characters are copied exactly "as-is". Out of the box - pure shell solution, no dependencies (except
- Set vi option in terminal:
set -o vi.
- Alias copying unclosed here-document:
alias c2c='cat - <<"" | tr -d '"'"'\n'"'"' | xsel -b'
- Write anything you want to the command line without pressing
<escape> followed by
<d>. Whole line should now disappear. To be able to type again, press
- Type name of the alias (
c2c in my example) and press
Voilà. Deleted text can be now pasted anywhere by pressing
<ctrl>+<v> (GUI), or
<ctrl>+<shift>+<v> (reasonable CLI). If Your CLI isn't reasonable, make it so.
Some likes like vi mode, others not really. But I think fuzzy finder is must have. It doesn't allow to do exactly what you've asked, it can do something better! Instead of "hitting up several times" fzf can browse command history with order of magnitude better efficiency. Moreover, it can be used inside my
c2c alias to copy to clipboard. Whatever is typed to the terminal at the moment cannot be nicely copied (without mouse), but if something is in history, it is a matter of seconds to get it.