From 589c3e06d8ac241f8ec3cdd1919a31cbe0c8737e Mon Sep 17 00:00:00 2001 From: hc Date: Tue, 10 Nov 2026 10:47:53 +0800 Subject: tmux, vimrc: non-blocking clipboard, yank to local and remote, prefix ] pastes remote then local --- core/tmux.conf | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'core/tmux.conf') diff --git a/core/tmux.conf b/core/tmux.conf index b9a6cb1..0304e94 100644 --- a/core/tmux.conf +++ b/core/tmux.conf @@ -40,23 +40,20 @@ set -g status-right "#{?pane_in_mode,line #{e|+:#{scroll_position},#{e|-:#{e|-:# # (replaces the default prefix + / "describe key"); capture goes via a named buffer so it targets this pane bind-key / capture-pane -J -S - -b scrollback \; display-popup -E -w 99% -h 99% "f=\$(mktemp); tmux save-buffer -b scrollback \$f; tmux delete-buffer -b scrollback; vim -M -c 'set number' + \$f; rm -f \$f" -# ===== Shared clipboard: RAM file /dev/shm/clip/buf on CLIP_HOST ===== +# ===== Clipboard: every yank goes to both places, neither blocks; prefix ] tries remote, then local ===== +# local: pbcopy on Mac, OSC 52 (set-clipboard on) everywhere; remote: RAM file /dev/shm/clip/buf on CLIP_HOST; copy-pipe runs as a background job %hidden CLIP_HOST="root@p.noml.ch" -# One persistent ssh link (opens on first use, one key touch). -# Close it: ssh -O exit -o ControlPath=~/.ssh/cm-%C %hidden CLIP="ssh -o ControlMaster=auto -o ControlPersist=yes -o ControlPath=~/.ssh/cm-%C -o ServerAliveInterval=30 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR $CLIP_HOST" -# push (yank): copy mode v to select, then y / Enter / mouse drag -%hidden YANK="$CLIP 'umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'" +%hidden YANK="f=\$(mktemp); cat >\$f; pbcopy <\$f 2>/dev/null; $CLIP 'umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf' <\$f >/dev/null 2>&1; rm -f \$f" bind-key -T copy-mode-vi v send-keys -X begin-selection # y = yank selection; with no selection, y y = yank the whole line bind-key -T copy-mode-vi y if-shell -F '#{selection_present}' { send-keys -X copy-pipe-no-clear "$YANK" } { switch-client -T copy-yy } bind-key -T copy-yy y send-keys -X select-line \; send-keys -X copy-pipe-no-clear "$YANK" bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "$YANK" bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YANK" -# pull (paste): prefix + ] fetches the buffer into tmux, then pastes it (-p: bracketed paste, so vim inserts it as-is even from normal mode); -# no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer -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" -# ===== end shared clipboard ===== +# prefix + ] pastes remote buffer; any remote failure or >3 s = Mac clipboard (Linux: tmux buffer); -b keeps tmux responsive meanwhile +bind-key ] run-shell -b "f=\$(mktemp); perl -e 'alarm 3; exec @ARGV' $CLIP '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf' >\$f 2>/dev/null || pbpaste >\$f 2>/dev/null || tmux save-buffer \$f; tmux load-buffer \$f; rm -f \$f; tmux paste-buffer -p -t '#{pane_id}'" +# ===== end clipboard ===== # OSC 52: copy-mode yanks also go to the clipboard of the terminal you type in; "on" (not "external") # also forwards OSC 52 that vim writes inside a pane set -g set-clipboard on -- cgit