diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/tmux.conf | 15 | ||||
| -rw-r--r-- | core/vimrc | 39 |
2 files changed, 12 insertions, 42 deletions
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|-:# | |||
| 40 | # (replaces the default prefix + / "describe key"); capture goes via a named buffer so it targets this pane | 40 | # (replaces the default prefix + / "describe key"); capture goes via a named buffer so it targets this pane |
| 41 | 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" | 41 | 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" |
| 42 | 42 | ||
| 43 | # ===== Shared clipboard: RAM file /dev/shm/clip/buf on CLIP_HOST ===== | 43 | # ===== Clipboard: every yank goes to both places, neither blocks; prefix ] tries remote, then local ===== |
| 44 | # 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 | ||
| 44 | %hidden CLIP_HOST="root@p.noml.ch" | 45 | %hidden CLIP_HOST="root@p.noml.ch" |
| 45 | # One persistent ssh link (opens on first use, one key touch). | ||
| 46 | # Close it: ssh -O exit -o ControlPath=~/.ssh/cm-%C <CLIP_HOST> | ||
| 47 | %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" | 46 | %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" |
| 48 | # push (yank): copy mode v to select, then y / Enter / mouse drag | 47 | %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" |
| 49 | %hidden YANK="$CLIP 'umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'" | ||
| 50 | bind-key -T copy-mode-vi v send-keys -X begin-selection | 48 | bind-key -T copy-mode-vi v send-keys -X begin-selection |
| 51 | # y = yank selection; with no selection, y y = yank the whole line | 49 | # y = yank selection; with no selection, y y = yank the whole line |
| 52 | 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 } | 50 | 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 } |
| 53 | bind-key -T copy-yy y send-keys -X select-line \; send-keys -X copy-pipe-no-clear "$YANK" | 51 | bind-key -T copy-yy y send-keys -X select-line \; send-keys -X copy-pipe-no-clear "$YANK" |
| 54 | bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "$YANK" | 52 | bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "$YANK" |
| 55 | bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YANK" | 53 | bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YANK" |
| 56 | # pull (paste): prefix + ] fetches the buffer into tmux, then pastes it (-p: bracketed paste, so vim inserts it as-is even from normal mode); | 54 | # prefix + ] pastes remote buffer; any remote failure or >3 s = Mac clipboard (Linux: tmux buffer); -b keeps tmux responsive meanwhile |
| 57 | # no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer | 55 | 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}'" |
| 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" | 56 | # ===== end clipboard ===== |
| 59 | # ===== end shared clipboard ===== | ||
| 60 | # OSC 52: copy-mode yanks also go to the clipboard of the terminal you type in; "on" (not "external") | 57 | # 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 | 58 | # also forwards OSC 52 that vim writes inside a pane |
| 62 | set -g set-clipboard on | 59 | set -g set-clipboard on |
| @@ -60,44 +60,17 @@ nnoremap <silent> <leader>f :<C-U>LspDocumentFormat<CR>| " \f: format file | |||
| 60 | nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor | 60 | nnoremap <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 | ||
| 64 | let g:clip_host = 'root@p.noml.ch' | 66 | let g:clip_host = 'root@p.noml.ch' |
| 65 | " One persistent ssh link (opens on first use, one key touch). | ||
| 66 | 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] | 67 | 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] |
| 67 | " push (yank): every yank or delete sends @" in a background job | 68 | augroup clipboard |
| 68 | augroup ssh_clipboard | ||
| 69 | au! | 69 | au! |
| 70 | au TextYankPost * call echoraw("\e]52;c;" . (exists('*str2blob') ? base64_encode(str2blob(split(@", "\n", 1))) : system("base64 | tr -d '\\n'", @")) . "\x07") | ||
| 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 | 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") | ||
| 73 | augroup END | 72 | augroup 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. | ||
| 78 | function! 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 | ||
| 93 | endfunction | ||
| 94 | for s:k in ['p', 'P', 'gp', 'gP', ']p', '[p'] | ||
| 95 | execute 'nnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''" | ||
| 96 | endfor | ||
| 97 | for s:k in ['p', 'P'] | ||
| 98 | execute 'xnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''" | ||
| 99 | endfor | ||
| 100 | " ===== end shared clipboard ===== | ||
| 101 | 74 | ||
| 102 | filetype plugin indent on | 75 | filetype plugin indent on |
| 103 | 76 | ||
