Live data from Hacker News

Yank: Yank Terminal Output to Clipboard

github.com

41–50 of 57 posts

Re: Yank: Yank Terminal Output to Clipboard

#41
post #33
post #25

Earlier quoted context omitted.

clip.exe works to and from WSL 2. But if you run VcXsrv you can use the native Linux clipboard and have it shared between WSL 2 and Windows. This is what I do because then tools like Vim, the pass utility and other command line tools can write to and read from the native Linux clipboard and everything will work out of the box. If you wanted to reproduce pbcopy / pbpaste in native Linux or WSL 2 you can set up aliases…

Oh that’s neat. Do you use the x server for just this purpose or do you also run linux gui apps? I’ve been thinking about investing more into it but the high dpi stuff does not work properly.

I use it just for the clipboard but I used to run Sublime Text through it years ago (using WSL 1). It was really fast and worked great, at least at 2560x1440.

A video walk through of my current Windows / WSL 2 / etc. dev environment is here: https://nickjanetakis.com/blog/a-linux-dev-environment-on-wi...

Re: Yank: Yank Terminal Output to Clipboard

#42
post #9

Earlier quoted context omitted.

> The only place I've seen the word "yank" in computing is in Emacs context, where it means "paste", not "copy"... This is a confusing difference between Emacs and Vim. Emacs uses it for pasting, Vim uses it for copying.

How did the Emacs developers ever thought "yank" would convey the meaning of "paste"? (Legitimate question. I'm aware some UX faux-pas do happen, but I don't see how)

Maybe Emacs yanks from a clipboard (into a buffer), while vim yanks from a buffer into a register (buffer)?

Re: Yank: Yank Terminal Output to Clipboard

#43
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

I think you'll unfortunately be left unsatisfied since there is no "simple" answer due to the way clipboards work in x11 and the historical baggage a lot of terminal apps drag with them (everyone did text-copying differently before ctrl-c and ctrl-v became ubiquitous).

A nice thing you can do in Vim though is to make the default clipboard the system clipboard like this in your .vimrc:

  set clipbaord=unnamedplus

Re: Yank: Yank Terminal Output to Clipboard

#44
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

I select and copy from Firefox and ctrl-shift insert pastes it into a terminal 95% of the time.

Rightclick paste always pastes it into a terminal.

Selecting in the terminal window and right click copying is the only way to reverse it which is pretty attrocious as I have to zoom way out and other shenanigans.

If any emacs-fu greybeards know of how to emacs Yank to the Gnome clipboard I will be eternally grateful.

caveat my terminal app is usually emacs.

Re: Yank: Yank Terminal Output to Clipboard

#45
post #38
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

clipboard = regular C-c and C-v stuff primary = highlight / middle click vim has its own used by default when you dd, p, etc. You can copy to one of the previous things (assuming your build enabled it) with "+y and "*y key sequences. You can also paste the same way, but I usually just let the term emu handle that with ctrl-shift-v or similar. shift-insert is kinda weird actually. AFAIK it should paste from selection,…

Vim has it's own clipboards by default (as mentioned) but you can also configure it to use the system clipboard.

    set clipboard=unnamedplus " Use system clipboard.
(I don't know if the exact name depends on OS but this works on Linux and IIRC macOS)

Re: Yank: Yank Terminal Output to Clipboard

#46
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

I think you'll unfortunately be left unsatisfied since there is no "simple" answer due to the way clipboards work in x11 and the historical baggage a lot of terminal apps drag with them (everyone did text-copying differently before ctrl-c and ctrl-v became ubiquitous). A nice thing you can do in Vim though is to make the default clipboard the system clipboard like this in your .vimrc: set clipbaord=unnamedplus

On another note, rebinding ctrl-c, ctrl-v, ctrl-s etc. in the terminal (including Vim) can be confusing, since most ctrl commands will be caught by stty (in most terminal emulators) and never passed on to the running application. If you really wanted to, you could rebind Vim's yank/paste to ctrl-c, ctrl-v by unbinding the stty commands.

  # 1. check the bindings for your system
  stty -a
  # 2. put the stuff you want to unbind in your shell rc file
  stty  undef
And then rebinding yank/paste in your .vimrc to only use your system clipboard.

This would, however, become painful as soon as you need to quickly use a machine remotely where all your local configs won't be present. It also generally raises the question why one is using Vim in the first place, if one is not planning to use its powerful features.

Re: Yank: Yank Terminal Output to Clipboard

#47

On Mac OS, a much less powerful but built in tool is `pbcopy`.

To replicate pbcoby on X11 systems, add to your bashrc: alias clip="xclip -selection clipboard" `echo hello | clip` will copy 'hello' to the clipboard, and similarly `ls | clip` will copy a bunch of lines to the clipboard. You might need to install xclip through your package manger (the package is just named xclip on Arch).

I like `xsel --clipboard` which Does The Right Thing by automatically deciding if it should copy or paste.

    # Paste clipboard into command.
    xsel --clipboard | grep foobar
    # Copy into clipboard
    grep foobar somefile.txt | xsel --clipboard
    # Transform clipboard.
    xsel --clipboard | tr A-Z a-z | xsel --clipboard
I find this so useful that I have it aliased to `c`.

Re: Yank: Yank Terminal Output to Clipboard

#48
post #2

Back in the day, on the Amstrad CPC, there was a way to duplicate the cursor, move the duplicate around on any part of the screen and copy any text below the duplicate to where the actual cursor was. I always thought that this simple but powerful feature was missing on modern computers. The submission is not equivalent but clearly can help avoid having to move your mouse around. Still wish I didn't have to modify the…

> I realize that I want to copy the command's output after I execute it.

With Zsh, cheating a little, you can achieve it with:

    _insert-last-command-output () {
        LBUFFER+="$(LS_COLORS= TERM=vt220 eval $history[$((HISTCMD-1))])"
    }
There's some junk used for my configuration, the relevant part is the "eval" of the last command on the history, it doesn't paste the output of the previous command but it's execute d again, this time with the output going straight in the edit buffer. I use it to manipulate the output of the previous command on the shell — it works better if the output is a single line — but I think it could be modified to put the output also on the clipboard...

Re: Yank: Yank Terminal Output to Clipboard

#49

On Mac OS, a much less powerful but built in tool is `pbcopy`.

I have used VM in Emacs to read my email for more than a quarter century. I run the Emacs session remotely, and open inline URLs locally on the Macbook I `mosh` out of. The remote machine connects to the local one and passes on the URL with `open`.

Sometimes I need the URL itself, as opposed to actually opening it. I wrote elisp to modify the command that displays the URL the cursor is over within Emacs to also use the above method, but use `pbcopy` to pass the URL onto the Mac clipboard.

Post reply on HN