I'm unable to get clipboard sharing with tmux working properly. I have this setting in my kitty.conf:
clipboard_control write-clipboard write-primary
When I select text in tmux's copy mode, it does not seem to get written to the system clipboard - when I paste using Cmd+V, the text copied in tmux does not get pasted.
I also tried it with clipboard_control read-clipboard write-clipboard read-primary write-primary but that did not help.
This works in iTerm when the "Applications in terminal may access clipboard" setting is turned on - is it something that is supported in kitty too?
I'm using macOS with kitty version 0.11.3.
You need to tell tmux to turn it on in the tmux settings.
Hmm, I didn't have to do this with iTerm - do you know which tmux setting it is?
EDIT: I ran tmux show-options -g -s set-clipboard which returned set-clipboard external, but it still does not work with kitty. Am I missing something?
I have no idea, I'm not a tmux user (IMO tmux is a horrible pile of hacks). All I can tell you is that OSC 52 works with kitty, which you can test by doing
printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"
and your clipboard will contain the string blaba
I see - thanks, I'll dig in a bit.
IMO tmux is a horrible pile of hacks
I find it quite nice, but have no strong preference - what alternative would you recommend?
I personally dont use a multiplexer at all. kitty itself has pretty much all the functionality of a multiplexer builtin, with the exception of remote persistence see #391
Oh and by the way, you can also use the clipboard kitten to more easily copy stuff to the keyboard, which uses OSC 52 under the hood
kitty +kitten clipboard --help
tmux resends OSC 52 to the outer terminal without the c parameter, like executing:
printf "\033]52;;$(printf "%s" "blabla" | base64)\a"
in kitty directly. kitty does not accept an empty clipboard parameter (which is allowed in the XTerm specs). Would it be possible to add support for empty clipboard paramters? It would make tmux users happy 馃槃 .
sure, done
Great, thanks! 馃憤
So, should this work now? I tried it but to no avail. I've set in my kitty.conf:
clipboard_control write-clipboard write-primary
And tried to execute this inside tmux:
echo test | kitty +kitten clipboard
But it doesn't end up in my system clipboard. It does outside tmux. I'm using kitty 0.13.3.
No idea. All I did was get kitty to accept without the c parameter, as described by @IngoHeimbach
I found an alternative solution though, in case anyone is interested:
https://github.com/tmux-plugins/tmux-yank
I have set
set -g set-clipboard on
in my .tmux.conf. When selecting text in tmux copy mode, tmux sends the text to the outer teminal with a OSC52 terminal sequence and kitty puts the text into the system clipboard.
But I don't know how
kitty +kitten clipboard
works internally. I think this command is not needed within tmux.
The clipboard kitten probably does not work because while tmux generates OSC 52 itself when copying, it does not pass it through when the program running inside it generates it.
Programs generating OSC52 should also work. I use a script that generates OSC52 for yanking text from vim to the system clipboard.
Well the clipboard kitten is just an easy to use API for generating OSC
52
Ok, I tried
echo "test" | kitty +kitten clipboard
within tmux which runs in kitty. For me, it works.
Not working for remote Tmux session.
Update: manually set osc52 sequence works, for now I managed to use a custom script to do so with Tmux. Something like:
printf "$esc" > $SSH_TTY
Also need git version that supports no-append as clipboard-option, otherwise it will only append to previous content.
I think Tmux's default osc52 may not be the compatible with kitty if it is running over SSH.
@hillyu You are right, by default tmux does not pass OSC52 if nested in another tmux session. The reason is the set TERM variable. If you use only one tmux instance your outer terminal probably sets TERM to xterm*. For xterm compatible terminals tmux enables OSC52 out of the box (Ms entry in options-table.c). If you nest tmux, the nested tmux instance gets the TERM value which is set by the outer tmux instance (probably screen* or tmux*). To get OSC52 working you have to add a Ms entry to the terminal-overrides option. You can try to add
set -ga terminal-overrides "screen*:Ms=\\E]52;%p1%s;%p2%s\\007,tmux*:Ms=\\E]52;%p1%s;%p2%s\\007"
to your .tmux.conf to enable OSC52 for a nested tmux session.
Thanks @IngoHeimbach , for pointing me to the right direction. I think the culprit for my setup is another override setting:
set -g terminal-overrides 'xterm*:smcup@:rmcup@'. If I enable this, tmux will not pass OSC52. However if I ssh to a remote server and launch tmux on that server, everything works. I don't usually nest tmux, but will test out using Ms entry override.
@IngoHeimbach i've got the issue that the copy content of tmux is always appended to the clipboard. The "no-append" option of the kitty "clipboard_control" config seems to be ignored. Any idea? Thx
@bastikempken I have tested the no-append option with v0.14.1 and it works for me. Are you sure you have the latest version of kitty installed?
I am having the same issue as @bastikempken
Copying within tmux seems to append it to the clipboard, and the no-append option does not help.
Does not occur in iTerm nor Alacritty. MacOS.
Which version of kitty are you using?
@Luflosi The latest release from brew cask.
~ kitty -v
kitty 0.14.2 created by Kovid Goyal

clipboard-control left on default. (no-append did nothing)
copy_on_select is set to no (has no difference either way)
I also cannot replicate, with set-clipboard on in tmux conf and running kitty as:
kitty -o clipboard_control=write-clipboard\ write-primary\ no-append
running
printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"
multiple times does not append to clipboard.
I'm sorry, it was my mistake. I didn't actually test the no-append option after upgrading kitty.
Thank you 馃檹
@gitaarik can you clarify your solution. I have tmux-yank but it does not solve this for me. Nothing is shared with system clipboard.
@jessebett it's an alternative solution, nothing to do with this thread. Better refer to the documentation or issues of tmux-yank if it's not working for you.
This worked for me on macOS...
# ~/.tmux.conf
- bind-key -T copy-mode-vi 'y' send -X copy-pipe "reattach-to-user-namespace pbcopy"
+ bind-key -T copy-mode-vi 'y' send -X copy-pipe "kitty +kitten clipboard"
To fix the problem of kitty defaulting to _appending_ to the clipboard (which seemed a strange default to set) I made the following modification...
# ~/.config/kitty/kitty.conf
clipboard_control write-clipboard write-primary no-append
This worked for me on macOS...
# ~/.tmux.conf - bind-key -T copy-mode-vi 'y' send -X copy-pipe "reattach-to-user-namespace pbcopy" + bind-key -T copy-mode-vi 'y' send -X copy-pipe "kitty +kitten clipboard"To fix the problem of kitty defaulting to _appending_ to the clipboard (which seemed a strange default to set) I made the following modification...
# ~/.config/kitty/kitty.conf clipboard_control write-clipboard write-primary no-append
Maybe something like this would be better? So the behaviour is consistent whether you use Kitty or another terminal
bind-key -T copy-mode-vi y if-shell "test ! -z $KITTY_WINDOW_ID" "send-keys -X copy-pipe 'kitty +kitten clipboard'" "send-keys -X copy-pipe 'pbcopy'"
Most helpful comment
This worked for me on macOS...
To fix the problem of kitty defaulting to _appending_ to the clipboard (which seemed a strange default to set) I made the following modification...