Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy/paste, SSH, Tmux #1569

Open
jpincas opened this issue Mar 11, 2020 · 11 comments
Open

Copy/paste, SSH, Tmux #1569

jpincas opened this issue Mar 11, 2020 · 11 comments

Comments

@jpincas
Copy link

jpincas commented Mar 11, 2020

I'm putting this here in the hope that it will help others in a similar situation. We're going all in on Micro for our shared cloud development environment and wanted to get copy/paste working well. After reading the micro help docs, stackoverflow etc, we finally came up with the following solution to get Micro over SSH inside tmux all working nicely. We're using Ubuntu on our local machines, as well as on the server:

  • close the ssh connection to your remote machine
  • create/edit .ssh/config on your local machine
  • add the line ForwardX11 yes
  • ssh into your remote machine
  • install xclip if it isn't already
  • close all your tmux sessions; unfortunately the above won't get through to existing sessions
  • start a new tmux session
  • do a check: echo "test" | xclip then xclip -o
  • likewise, check the 'bridge' with your local machine's clipboard by copying text from a local app like a browser and then running xclip -o on your remote tmux session
  • you can also do echo "something" | xclip and paste it somewhere on your local machine
  • check copy/paste works inside a single Micro instance by using the stanard Micro copy/paste keybindinds; i.e. ctrl+c, ctrl+v
  • check copy/paste works across Micro instances in different tmux panes
@jpincas
Copy link
Author

jpincas commented Mar 12, 2020

I should add something else.

Micro uses the xclip 'clipboard' selection, whereas xclip on the command line defaults to 'primary'. Therefore, we find it most convenient to create these alias:

alias copy="xclip -selection clipboard"
alias paste="xclip -o -selection clipboard" 

This basically unifies copy/paste between micro, your remote command line, tmux and your local system.

@jpincas
Copy link
Author

jpincas commented Mar 14, 2020

Quick tip. Using the above setup, there is a slight, but significant, delay when pasting in Micro (i guess due to various layers the paste is having to go through). You can avoid this by just using the 'terminal level' paste key combo: shift+ctrl+v. This pastes instantly.

@jpincas
Copy link
Author

jpincas commented Mar 18, 2020

Ive now patched the author's clipboard package to work very nicely with the tmux buffers - I believe this is the best solution for tmux users. Im using it on a daily basis and it appears to work very well. I'll open a PR.

@jn64
Copy link

jn64 commented May 29, 2020

Thanks for the instructions, it helped me.

Just a note that paste is an existing command provided by GNU coreutils, which many users might have installed by default.

@tlaerm
Copy link

tlaerm commented Oct 29, 2020

Thank you for this.

@MJavad
Copy link

MJavad commented Feb 20, 2021

Ive now patched the author's clipboard package to work very nicely with the tmux buffers - I believe this is the best solution for tmux users. Im using it on a daily basis and it appears to work very well. I'll open a PR.

I’m looking for something like this, did you get around to submitting the PR? I couldn’t find it.

@avently
Copy link

avently commented Jan 28, 2022

I found another solution for this problem when you have X server running on a remote machine.
When I run:

xclip

on remote machine via SSH I get Error: Can't open display: (null)

This is a hint actually.

I did:

alias m = 'DISPLAY=:0 micro'

And micro copy-paste works good. Try it. Years of pain are gone:)

Another task is to find a work around the problem without X server running and without X server forwarding.

@avently
Copy link

avently commented Jun 6, 2022

Another solution (now it works without X11 running).

All info is here: https://github.com/tmux/tmux/wiki/Clipboard
TLDR: write this text in tmux.conf

set-option -g set-clipboard on

This will allow external programs like micro to fill clipboard. Works awesome.

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Jan 18, 2023

My original message 18 Jan. 2023:

Quick tip. Using the above setup, there is a slight, but significant, delay when pasting in Micro (i guess due to various layers the paste is having to go through). You can avoid this by just using the 'terminal level' paste key combo: shift+ctrl+v. This pastes instantly.

Using Ctrl + Shift + V speeds up paste time, but there is still a pretty significant delay in
Ctrl + C copy time, and Ctrl + Shift + C doesn't work for me in micro (in the terminator terminal when editing over ssh, at least). Any idea how to eliminate or improve that delay? The delay is probably a full second when copying (tested while ssh'ed into a remote machine), and for a command-line tool, that feels like forever.

Update 25 Jan. 2023:

Copy/paste is fast over ssh until I do sudo apt install xclip on the remote machine to allow me to copy/paste from my local machine to my remote micro editor running over ssh on the remote machine. Once I do sudo apt install xclip on the remote machine, copy/paste is dreadfully slow. :( If I do sudo apt remove xclip on the remote machine, copy/paste immediately speeds back up again.

In my experimenting, xsel is about 2 to 3x slower than xclip. Normal copy/paste delay with neither of those installed is unnoticeable over ssh, but I can't copy from micro on the remote machine over ssh and paste to my local machine. Once I install xclip or xsel, I can. But, xclip adds a copy and paste delay of ~0.5 sec, and xsel adds a copy and paste delay of ~1+ sec, which is really obnoxious.

Update again: here is a detailed write-up of my solution:

How to copy/paste to/from a remote machine running micro over ssh to/from your local machine

@ElectricRCAircraftGuy
Copy link

Ive now patched the author's clipboard package to work very nicely with the tmux buffers - I believe this is the best solution for tmux users. Im using it on a daily basis and it appears to work very well. I'll open a PR.

@jpincas , did you open a PR?

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Jan 27, 2023

It turns out micro has this copy/paste informational article here too: https://github.com/zyedidia/micro/blob/master/runtime/help/copypaste.md

Thanks @DoTheEvo for pointing it out to me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants