summaryrefslogtreecommitdiff
path: root/core/vimrc
diff options
context:
space:
mode:
authorhc <haocheng.xie@respiree.com>2026-11-10 10:47:53 +0800
committerhc <haocheng.xie@respiree.com>2026-11-10 10:47:53 +0800
commit589c3e06d8ac241f8ec3cdd1919a31cbe0c8737e (patch)
treec50a9b1abc422676ab15ba5f52c432ecae3b7646 /core/vimrc
parent402a854a195ea1e63c622edeee5dbbc802441d53 (diff)
tmux, vimrc: non-blocking clipboard, yank to local and remote, prefix ] pastes remote then localHEADmain
Diffstat (limited to 'core/vimrc')
-rw-r--r--core/vimrc39
1 files changed, 6 insertions, 33 deletions
diff --git a/core/vimrc b/core/vimrc
index 26ebdb6..93608ce 100644
--- a/core/vimrc
+++ b/core/vimrc
@@ -60,44 +60,17 @@ nnoremap <silent> <leader>f :<C-U>LspDocumentFormat<CR>| " \f: format file
60nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor 60nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor
61 61
62 62
63" ===== Shared clipboard: RAM file /dev/shm/clip/buf on g:clip_host (same as tmux.conf) ===== 63" ===== Clipboard: every yank goes to both places, neither blocks; paste is always local =====
64" local: OSC 52 sends @" to the terminal you type in (inside tmux needs set-clipboard on)
65" remote: background ssh job writes @" to RAM file /dev/shm/clip/buf on g:clip_host; failure is silent
64let g:clip_host = 'root@p.noml.ch' 66let g:clip_host = 'root@p.noml.ch'
65" One persistent ssh link (opens on first use, one key touch).
66let g: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', g:clip_host] 67let g: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', g:clip_host]
67" push (yank): every yank or delete sends @" in a background job 68augroup clipboard
68augroup ssh_clipboard
69au! 69au!
70au TextYankPost * call echoraw("\e]52;c;" . (exists('*str2blob') ? base64_encode(str2blob(split(@", "\n", 1))) : system("base64 | tr -d '\\n'", @")) . "\x07")
70au 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) 71au 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)
72au TextYankPost * call echoraw("\e]52;c;" . system("base64 | tr -d '\\n'", @") . "\x07")
73augroup END 72augroup END
74" pull (paste): every p P gp gP ]p [p (normal) and p P (visual) first fetches the buffer into @". 73" ===== end clipboard =====
75" Waits up to 3 s for a pending push, then up to 3 s for the fetch (perl alarm kills ssh);
76" no buffer on g:clip_host yet (exit 3, e.g. after its reboot) = normal local paste;
77" any other failure prints a message and skips the paste. Counts and "x register prefixes still work.
78function! ClipPull() abort
79 let l:i = 0
80 while exists('g:clip_job') && job_status(g:clip_job) ==# 'run' && l:i < 30
81 sleep 100m
82 let l:i += 1
83 endwhile
84 let l:out = system("perl -e 'alarm 3; exec @ARGV' " . join(g:clip) . " '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf'")
85 if v:shell_error == 3
86 return 1
87 elseif v:shell_error
88 echohl ErrorMsg | echo 'clip: pull from ' . g:clip_host . ' failed or took >3s, paste skipped' | echohl None
89 return 0
90 endif
91 call setreg('"', l:out)
92 return 1
93endfunction
94for s:k in ['p', 'P', 'gp', 'gP', ']p', '[p']
95 execute 'nnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''"
96endfor
97for s:k in ['p', 'P']
98 execute 'xnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''"
99endfor
100" ===== end shared clipboard =====
101 74
102filetype plugin indent on 75filetype plugin indent on
103 76