Hacker News new | past | comments | ask | show | jobs | submit login

Bash and Zsh provide shortcuts to open a text editor where commands can be pasted and edited before running (Ctrl-x Ctrl-e in bash, need to enable in zsh [2]). I've been using this on Linux not for security but because I'm still confused by X11's primary and clipboard selections [1]. It seems like every time I try to paste a github repo link, I get the last chunk of code I copied and vice versa.

[1] http://www.nongnu.org/autocutsel/

[2] Sample .zshrc to map edit-command-line to Ctrl-x e:

  autoload edit-command-line
  zle -N edit-command-line
  bindkey '^Xe' edit-command-line
edit: fixed shortcut for bash

edit: forgot about my .zshrc

Out of interest, what is confusing? If you select text it always goes into the selection buffer. If you also press the clipboard copy shortcut (so, Ctrl-C most of the time, sometimes Ctrl-Shift-C in a terminal) the selection is copied into the clipboard buffer.

Ctrl-V (or, again, sometimes Ctrl-Shift-V in a terminal) pastes the clipboard buffer. Middle mouse button (or shift-Insert) pastes the selection buffer.

Is there still room for confusion?

Firefox causes additional confusion by rebinding Ctrl+Insert to what Ctrl+v usually does (copying the clipboard buffer, not the selection buffer).

Also there are some cases where javascript which selects text for you causes very unintuitive behavior wrt selection buffer.

Just one more reason to abandon the extraordinary towering failure that is Firefox ;)

I think "confusing" in this context doesn't mean that the concepts are hard to enumerate or understand, it means they're hard to apply with low error rate in a practical setting.

I don't have a problem with X selection+paste if I'm just using Linux. But using it when connected to a remote machine via various remoting technologies (NX, Chrome Remote Desktop), and then mix in that the host machine is a Mac with its terrible command/control split, and the result is pretty confusing.

I use rxvt and never figured out how to paste the clipboard buffer, so I use shift-insert to paste the primary buffer. Unfortunately, the primary buffer can be overwritten without my consent, e.g. an autofocused web input field.

Vim and emacs also have their own shortcuts for accessing the clipboard buffer.

You might find urxvt-perls useful, amongst the useful things it offers is clipboard interaction.


Thanks for the link. I'll find a place for uxvrt-perls in my hacky copy-paste workflow. I'm currently using tmux paste buffers and shell functions around xclip to move around text.

> If you select text it always goes into the selection buffer.

But as far as I can tell, if text is selected for you that's not always true. I sometimes have difficulty with text boxes which insist on self-selecting as soon as I click them, and which I just can't seem to pull into the selection buffer.

Github doesn't seem to have this issue, but I had recently when trying to get a google maps permalink, for example.

Yeah, copying GitHub URLs sucks. You cannot actually select it with your mouse, since some creepy JavaScript interferes and selects it for you. the result is that it's selected, but not copied to PRIMARY, as you'd expect. I fall into this trap every single time.

Being pissed off as I always fall into the trap, last week I wrote a userscript that adds a 'clone' button to gh webs.

Combined with xdg-open, I clone the repos locally just clicking the 'Clone' link.


Userscript itself in: https://github.com/kidd/org-protocol-github-lines/blob/clone...

Ctrl-x e in zsh is '_expand_word'. The function you are talking about is 'edit-command-line', which is not loaded or bound to any key by default in zsh. You have to load it manually.

Thanks, edited my post

Every once in a while I think I have my shell environment set up exactly the way I want it. Then I find out about something like this - thanks for the tip.

Ctrl-X + E doesn't appear to be doing anything in bash.

It's Ctrl-X-E (both with Ctrl)

Thanks, forgot about bash behavior. On Zsh the 'e' doesn't need to be pressed with control.

Woah :)

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact