For example, supposed I'm browsing through my history, and reach this multi-line command I'd typed earlier:

~ >> for f in *; do
echo $f
done

I've enabled vim bindings in the ZLE (bindkey -v), so I can type Esc at this point and use vim keys to get around, move across lines, etc. I can also do yy to yank the current line. However, there doesn't seem to be an obvious way to copy all these lines.

Any ideas?

There are two (admittedly cumbersome) approaches that come to mind. The first is to use Vim, the second a small utility for Urxvt (if that is your terminal emulator):

  • While in your history, hit v to open the current command in your $EDITOR (which is Vim, naturally) and then Shiftvg to select all of the lines before "+* to yank it to your clipboard.

  • You could also use urxvt-perls for this (and other) enhanced functionality in the terminal, including yanking and pasting. In this case: AltEscape to enter selection mode, Shiftv, 2k to select all of the lines and y to yank them to the buffer, before q to quit. ShiftInsert pastes the yanked text.1

The first approach seems the most direct, assuming there isn't some straightforward way to do it just using Zsh's line editing capability.2


1. These keybinds are all configurable in your ~/.Xresources
2. Which wouldn't surprise me...

  • Yes, I did think of the $EDITOR approach, but as you said, that is quite cumbersome. I'd prefer not having a terminal emulator based approach, since I split my time between iTerm2 on Mac and gnome-terminal on an Ubuntu box. – Milind Ganjoo Nov 23 '13 at 0:57
  • @MilindGanjoo Yes, I'm looking forward to an answer that just use Zle myself... – jasonwryan Nov 23 '13 at 1:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.