-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Sync tmux clipboard and system clipboard #1343
Conversation
if config.tmux_system_clipboard { | ||
command_provider! { | ||
// Refresh tmux clipboard, wait a bit for it to be updated and paste it | ||
paste => "sh", "-c", "tmux refresh-client -l; sleep 0.1; tmux save-buffer -"; | ||
copy => "tmux", "load-buffer", "-w", "-"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a editor.clipboard.paste
/editor.clipboard.copy
(now that I think about it, copy
-> yank
) section to the configuration? That way you're able to set this in config.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, ideally I’d like the clipboard to just work out of the box. (Apart from this PR, there’s also OSC 52 support missing (which are terminal escape sequences), they are needed to support copy and paste e.g. in alacritty through ssh.)
How do you propose should the config look like if these commands should be used inside tmux, but the other built-in commands should be used outside tmux, e.g. when DISPLAY is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that config is enabled but tmux is not enabled won't it have an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean with the tmux-system-clipboard
from this PR? That shouldn’t be a problem. It’s only used when helix is running inside tmux.
With editor.clipboard.paste
commands set in the config that are executed regardless of the environment that helix runs in, that would be a problem.
Rebased, no other changes |
I don't like the delay this adds to pasting, it feels like a hack. Is there no better way to do this with tmux? |
I don’t like it either, but I don’t know of a better way with tmux commands. As mentioned, the problem of not knowing when the clipboard updated exists when using tmux commands, but it can be circumvented by using a different method. There are the OSC 52 escape sequences that allow clipboard access by communicating with the terminal emulator.
Using OSC 52 to access the clipboard would be quite nice as it works when running helix over ssh, which currently doesn’t work (ssh -> tmux -> helix works with this patch though). |
When copying, also write the content into the system clipboard. When pasting, request tmux to refresh its paste buffer from the system clipboard, wait for the update to propagate and the request the clipboard content from tmux. With `set -g set-clipboard on` in tmux, this enables sharing the system clipboard with a helix running in tmux, running in an ssh session, running in alacritty. The need for a wait is unfortunate, but I didn't find a better way. Tmux asks the terminal for the clipboard content and updates its buffer after it got an answer. The answer may come or may not. It may take long, e.g. when running through a slow ssh connection. The feature works well on alacritty. On konsole, it doesn't do anything, but doesn't harm either. On xterm, `tmux refresh-client -l` prints gibberish for me, also without using helix, so I added an option to disable this feature.
43148b4
to
e3450ca
Compare
So I guess now we just wait for OSC 52 and then only come back to this? |
Resolved by #5027 |
#5027 only fixes the copy-path, not pasting. But as pasting works with |
When copying, also write the content into the system clipboard.
When pasting, request tmux to refresh its paste buffer from the system
clipboard, wait for the update to propagate and the request the
clipboard content from tmux.
With
set -g set-clipboard on
in tmux, this enables sharing thesystem clipboard with a helix running in tmux, running in an ssh
session, running in alacritty.
The need for a wait is unfortunate, but I didn't find a better way.
Tmux asks the terminal for the clipboard content and updates its buffer
after it got an answer. The answer may come or may not. It may take
long, e.g. when running through a slow ssh connection.
The feature works well on alacritty. On konsole, it doesn't do
anything, but doesn't harm either. On xterm,
tmux refresh-client -l
prints gibberish for me, also without using helix, so I added an
option to disable this feature.