In Bash and other shells in emacs mode, there are these awesome kill/yank shortcuts (see man readline), for example:

  • Ctrl+k: "kill-line": this deletes (and save into a cut buffer) all the current line before the cursor.
  • Ctrl+y: "yank" will paste under the cursor the last deleted content.
  • Alt+y: "yank-pop" will cycle through previous deleted content.

However I am in a situation where I want to:

  1. hit Ctrl+k,
  2. do stuff (type other commands),
  3. and then paste back the original line, but only if there was any content!

In the current settings, hitting Ctrl+k on an empty line leaves the cut buffer unchanged, so hitting Ctrl+y does not *restore* the original line.

I can't find how to clear this kill ring, is it doable (apart from switching to zsh...)?

  • 1
    A workaround is to kill the content+"a", then on paste delete that "a" character. Only works for automated binding (although I suppose that there's no reason to paste back an empty command when it's done manually)
    – user202729
    Commented Jun 3, 2020 at 9:59
  • Clever. It's indeed for automation. The aim was to invisibly use a feature of tmux-resurrect, which saves panel history by sending commands to the terminals (I wanted to back up partially filled lines). I found a way using tput smcup/tput rmcup which enters/quits a second terminal buffer O.o ... Commented Jun 3, 2020 at 11:19

1 Answer 1


No -- kill ring is never cleared by readline library (used by bash), so there's no bindable command for that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .