diff options
| author | xs <xs@xs.local> | 2026-11-10 09:39:10 +0800 |
|---|---|---|
| committer | xs <xs@xs.local> | 2026-11-10 09:39:10 +0800 |
| commit | 402a854a195ea1e63c622edeee5dbbc802441d53 (patch) | |
| tree | 70529d4479db1509eccbc5845a80d51e9cb9a8c7 /core | |
| parent | 20e382dec315fb23bb3dda787247312fc355df9a (diff) | |
tmux, vimrc: yanks also go to the local terminal clipboard via OSC 52
tmux: set-clipboard on, so OSC 52 written by vim inside a pane is forwarded
to the client terminal (external dropped it). vimrc: TextYankPost writes @"
as OSC 52 next to the existing ssh push; base64 via the base64 command since
base64_encode()/str2blob() are newer than vim 9.1.83.
Diffstat (limited to 'core')
| -rw-r--r-- | core/tmux.conf | 4 | ||||
| -rw-r--r-- | core/vimrc | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/core/tmux.conf b/core/tmux.conf index 0093aaa..b9a6cb1 100644 --- a/core/tmux.conf +++ b/core/tmux.conf | |||
| @@ -57,7 +57,9 @@ bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YAN | |||
| 57 | # no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer | 57 | # no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer |
| 58 | bind-key ] run-shell "f=\$(mktemp); $CLIP '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf' >\$f; r=\$?; [ \$r -eq 0 ] && tmux load-buffer \$f; rm -f \$f; [ \$r -eq 0 ] || [ \$r -eq 3 ] && tmux paste-buffer -p" | 58 | bind-key ] run-shell "f=\$(mktemp); $CLIP '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf' >\$f; r=\$?; [ \$r -eq 0 ] && tmux load-buffer \$f; rm -f \$f; [ \$r -eq 0 ] || [ \$r -eq 3 ] && tmux paste-buffer -p" |
| 59 | # ===== end shared clipboard ===== | 59 | # ===== end shared clipboard ===== |
| 60 | # TODO: try `set -g set-clipboard off` later (tmux default "external" sends copies to the local terminal clipboard via OSC 52); unrelated to the shared clipboard above | 60 | # OSC 52: copy-mode yanks also go to the clipboard of the terminal you type in; "on" (not "external") |
| 61 | # also forwards OSC 52 that vim writes inside a pane | ||
| 62 | set -g set-clipboard on | ||
| 61 | 63 | ||
| 62 | # Linux only: true-color regardless of what TERM the outer terminal/distro sets | 64 | # Linux only: true-color regardless of what TERM the outer terminal/distro sets |
| 63 | if-shell 'uname | grep -q Darwin' {} { | 65 | if-shell 'uname | grep -q Darwin' {} { |
| @@ -68,6 +68,8 @@ let g:clip = ['ssh', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=yes', '-o | |||
| 68 | augroup ssh_clipboard | 68 | augroup ssh_clipboard |
| 69 | au! | 69 | au! |
| 70 | au TextYankPost * let g:clip_job = job_start(g:clip + ['umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'], {'in_io': 'pipe', 'out_io': 'null', 'err_io': 'null'}) | call ch_sendraw(g:clip_job, @") | call ch_close_in(g:clip_job) | 70 | au TextYankPost * let g:clip_job = job_start(g:clip + ['umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'], {'in_io': 'pipe', 'out_io': 'null', 'err_io': 'null'}) | call ch_sendraw(g:clip_job, @") | call ch_close_in(g:clip_job) |
| 71 | " also OSC 52: @" to the clipboard of the terminal you type in (inside tmux needs set-clipboard on) | ||
| 72 | au TextYankPost * call echoraw("\e]52;c;" . system("base64 | tr -d '\\n'", @") . "\x07") | ||
| 71 | augroup END | 73 | augroup END |
| 72 | " pull (paste): every p P gp gP ]p [p (normal) and p P (visual) first fetches the buffer into @". | 74 | " pull (paste): every p P gp gP ]p [p (normal) and p P (visual) first fetches the buffer into @". |
| 73 | " Waits up to 3 s for a pending push, then up to 3 s for the fetch (perl alarm kills ssh); | 75 | " Waits up to 3 s for a pending push, then up to 3 s for the fetch (perl alarm kills ssh); |
