diff options
| author | xs <xs@xs.local> | 2026-11-05 10:45:29 +0800 |
|---|---|---|
| committer | xs <xs@xs.local> | 2026-11-05 10:45:32 +0800 |
| commit | bbe55a3f647f07a6b7c9852a499c45d03ac068af (patch) | |
| tree | c35e6da0cb789718ad026e8ef2be28a4fb77102d /core/vimrc | |
| parent | dc1ff54f7290a42ae440389141401b78ed76d473 (diff) | |
core: shared clipboard over ssh to root@p.noml.ch
tmux.conf and vimrc push yanks to /dev/shm/clip/buf on CLIP_HOST
(root@p.noml.ch) and pull before every paste (tmux prefix+], every vim
p variant, 3 s limit, local paste when no buffer exists yet). One
persistent ssh link per machine (ControlPersist=yes, ControlPath
~/.ssh/cm-%C), host key not checked. Replaces the openssl+netcat sender.
vimrc: set nocompatible so /etc/vimrc parses \ continuations and <leader>.
Diffstat (limited to 'core/vimrc')
| -rw-r--r-- | core/vimrc | 37 |
1 files changed, 35 insertions, 2 deletions
| @@ -1,5 +1,6 @@ | |||
| 1 | " One vimrc for Mac and Linux. Source of truth: /Users/xs/dev_env/core/vimrc | 1 | " One vimrc for Mac and Linux. Source of truth: /Users/xs/dev_env/core/vimrc |
| 2 | " Mac: cp core/vimrc ~/.vimrc Linux: sudo bash core/vim.sh (copies it to /etc/vimrc or /etc/vim/vimrc) | 2 | " Mac: cp core/vimrc ~/.vimrc Linux: sudo bash core/vim.sh (copies it to /etc/vimrc or /etc/vim/vimrc) |
| 3 | set nocompatible " /etc/vimrc is read before vim leaves vi mode; without this \ continuations and <leader> break | ||
| 3 | " gt: go to next tab (right, wraps) | 4 | " gt: go to next tab (right, wraps) |
| 4 | " gT: go to previous tab (left, wraps) | 5 | " gT: go to previous tab (left, wraps) |
| 5 | " 2gt: go to tab number 2 (counted from 1 at the left) | 6 | " 2gt: go to tab number 2 (counted from 1 at the left) |
| @@ -53,10 +54,42 @@ nnoremap <silent> <leader>f :<C-U>LspDocumentFormat<CR>| " \f: format file | |||
| 53 | nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor | 54 | nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor |
| 54 | 55 | ||
| 55 | 56 | ||
| 56 | augroup netcat_clipboard | 57 | " ===== Shared clipboard: RAM file /dev/shm/clip/buf on g:clip_host (same as tmux.conf) ===== |
| 58 | let g:clip_host = 'root@p.noml.ch' | ||
| 59 | " One persistent ssh link (opens on first use, one key touch). | ||
| 60 | let 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] | ||
| 61 | " push (yank): every yank or delete sends @" in a background job | ||
| 62 | augroup ssh_clipboard | ||
| 57 | au! | 63 | au! |
| 58 | au TextYankPost * call system("echo " . shellescape(@") . " | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1 &") | 64 | 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) |
| 59 | augroup END | 65 | augroup END |
| 66 | " pull (paste): every p P gp gP ]p [p (normal) and p P (visual) first fetches the buffer into @". | ||
| 67 | " Waits up to 3 s for a pending push, then up to 3 s for the fetch (perl alarm kills ssh); | ||
| 68 | " no buffer on g:clip_host yet (exit 3, e.g. after its reboot) = normal local paste; | ||
| 69 | " any other failure prints a message and skips the paste. Counts and "x register prefixes still work. | ||
| 70 | function! ClipPull() abort | ||
| 71 | let l:i = 0 | ||
| 72 | while exists('g:clip_job') && job_status(g:clip_job) ==# 'run' && l:i < 30 | ||
| 73 | sleep 100m | ||
| 74 | let l:i += 1 | ||
| 75 | endwhile | ||
| 76 | 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'") | ||
| 77 | if v:shell_error == 3 | ||
| 78 | return 1 | ||
| 79 | elseif v:shell_error | ||
| 80 | echohl ErrorMsg | echo 'clip: pull from ' . g:clip_host . ' failed or took >3s, paste skipped' | echohl None | ||
| 81 | return 0 | ||
| 82 | endif | ||
| 83 | call setreg('"', l:out) | ||
| 84 | return 1 | ||
| 85 | endfunction | ||
| 86 | for s:k in ['p', 'P', 'gp', 'gP', ']p', '[p'] | ||
| 87 | execute 'nnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''" | ||
| 88 | endfor | ||
| 89 | for s:k in ['p', 'P'] | ||
| 90 | execute 'xnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''" | ||
| 91 | endfor | ||
| 92 | " ===== end shared clipboard ===== | ||
| 60 | 93 | ||
| 61 | filetype plugin indent on | 94 | filetype plugin indent on |
| 62 | 95 | ||
