tmux.vim (2373B)
1 vim9script 2 3 def TmuxSendKeysToMarkedVisual() 4 var a_save = @a 5 try 6 silent execute 'normal! "ay' 7 call system("tmux load-buffer -", @a) 8 call system("tmux paste-buffer -p -t {marked}") 9 finally 10 @a = a_save 11 endtry 12 enddef 13 14 def TmuxSendKeysToMarkedNormal(type: string) 15 var a_save = @a 16 try 17 if type == 'line' 18 silent execute "normal! '[V']\"ay" 19 elseif type == "char" 20 silent execute "normal! `[v`]\"ay" 21 elseif type == "block" 22 silent execute "normal! `[\<C-v>`]\"ay" 23 endif 24 call system("tmux load-buffer -", @a) 25 call system("tmux paste-buffer -p -t {marked}") 26 finally 27 @a = a_save 28 set operatorfunc= 29 endtry 30 enddef 31 32 def TmuxSetBufferVisual() 33 var a_save = @a 34 try 35 silent execute 'normal! "ay' 36 call system("tmux load-buffer -", "\e[200~" .. @a .. "\e[201~") 37 call system("tmux paste-buffer -t {marked}") 38 finally 39 @a = a_save 40 endtry 41 enddef 42 43 def TmuxSetBufferNormal(type: string) 44 var a_save = @a 45 try 46 if type == 'line' 47 silent execute "normal! '[V']\"ay" 48 elseif type == "char" 49 silent execute "normal! `[v`]\"ay" 50 elseif type == "block" 51 silent execute "normal! `[\<C-v>`]\"ay" 52 endif 53 call system("tmux load-buffer -", @a) 54 finally 55 @a = a_save 56 set operatorfunc= 57 endtry 58 enddef 59 60 nmap <silent> <localleader>tb <Cmd>set operatorfunc=<SID>TmuxSetBufferNormal<CR>g@ 61 vmap <silent> <localleader>tb <ScriptCmd>TmuxSetBufferVisual()<CR> 62 nmap <silent> <localleader>ts <Cmd>set operatorfunc=<SID>TmuxSendKeysToMarkedNormal<CR>g@ 63 vmap <silent> <localleader>ts <ScriptCmd>TmuxSendKeysToMarkedVisual()<CR> 64 65 nmap <silent> <localleader>te <ScriptCmd>system('tmux send-keys -t {marked} Enter')<CR> 66 nmap <silent> <localleader>tc <ScriptCmd>system('tmux send-keys -t {marked} <C-c>')<CR> 67 nmap <silent> <localleader>td <ScriptCmd>system('tmux send-keys -t {marked} <C-d>')<CR> 68 69 # Python 70 nmap <silent> <localleader>tpi <ScriptCmd>system('tmux send-keys -t {marked} python Enter')<CR> 71 nmap <silent> <localleader>tpa <ScriptCmd>system('tmux send-keys -t {marked} ". venv/bin/activate"')<CR> 72 73 # R 74 nmap <silent> <localleader>tri <ScriptCmd>system('tmux send-keys -t {marked} R Enter')<CR> 75 76 # vim: et sts=4 sw=4