micro
micro copied to clipboard
Copy/paste, SSH, Tmux
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
thenxclip -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
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.
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.
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.
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.
Thank you for this.
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.
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.
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.
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
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?
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.