I'm using zsh + rxvt-unicode as a terminal simulator in Archlinux. I've successfully setup navigation in the terminal using Ctrl+Arrow keys, but I can't setup the terminal to be able to select text when pressing Shift + Arrow (or Ctrl + Shift + Arrow to select the whole word). After several days of searching for solution I couldn't find one. Enabling keyboard-select in .Xresources didn't do the trick. So I'm interested in what should I do to be able to select text in the console without using the mouse just like it is done in all text editors?

Do you want zsh to receive the Ctrl+Shift+Arrow key presses, or do you want to select text displayed in the terminal to copy it to the X clipboard? What key sequences do Ctrl+Arrow and Ctrl+Shift+Arrow send?
–
GillesJan 14 '13 at 0:24

@Gilles I want to select text to be able to copy it. Just like this is done in ubuntu - pressing Ctrl + Arrow highlights the text in terminal and pressing Ctrl+Shift+C copies it to clipboard. ^[Od - Ctrl + Left ^[[d - Ctrl + Shift + Left ^[Oc - Ctrl + Right ^[[c - Ctrl + Shift + Right
–
RomanKapitonovJan 14 '13 at 0:34

You seem to be describing a feature of Gnome Terminal. I don't think rxvt has this feature.
–
GillesJan 14 '13 at 0:43

@Gilles I always thought this is a kind of basic feature
–
RomanKapitonovJan 14 '13 at 0:56

Beware that targeting resources to rxvt-unicode can be rather tricky. Are you able to set any OTHER resources except keyboard-select (and see the effects)?
–
dan3Jan 14 '13 at 8:57

1 Answer
1

Put URxvt*altSendsEscape: true in ~/.Xresources, then xrdb ~/.Xresources in ~/.xinitrc.

For xterm, in ~/.Xresources, put xterm*metaSendsEscape: true.

For rxvt, my intuition tells me it looks identical or very similar.

Step 2. Patching cursor movement

This will give you the Emacs meta key, so you won't have to reach for Escape. I set this up when using bash, and got it to work, and then switched to zsh; it still worked, but, as for word movement with the Emacs keybindings, it seems zsh and bash are somewhat different: the closest I got to Emacs behaviour, I got with this patch. If you're used to Emacs, it is very handy to have the same cursor movement in the shell.

Now, for example, set the mark with C-SPC, mark the previously typed word with M-b, kill it with C-w (or, without erasing it, with M-w), yank it with C-y, and so on.

OK, I know you wanted Ctrl-Left and so on, but that is a huge downtrade: that way, you have to reach for every cursor movement, and reach back to resume typing. There is a big annoyance and productivity drop! The "new" (but better) shortcuts are stiff in the beginning, but I'd advice anyone, just force yourself to use them, in no time (as you type all the time!), they'll come naturally.

The reason for this is, I couldn't find a way to hook Emacs to a zsh alias, although I suspect that is possible. Anyhow, invoke with M-x pst.

EDIT

I added this workaround to make Emacs forward-char as many characters as you just inserted. (The first piece of code below is the script - see above - that has changed, too.) I use an intermediate file to do this - though, as a programmer, this goes against my intuition (as a bad habit), but, well, it seems to work. Obviously, the end-of-line (in my first answer) wasn't good as sometimes you want to insert a single word in the middle of a sentence.