vimrc

My Vim config
git clone git://pcardenasb.com/vimrc
Log | Files | Refs | Submodules

tmux.vim (2885B)


      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 -", @a)
     37     finally
     38         @a = a_save
     39     endtry
     40 enddef
     41 
     42 def TmuxSetBufferNormal(type: string)
     43     var a_save = @a
     44     try
     45         if type == 'line'
     46             silent execute "normal! '[V']\"ay"
     47         elseif type == "char"
     48             silent execute "normal! `[v`]\"ay"
     49         elseif type == "block"
     50             silent execute "normal! `[\<C-v>`]\"ay"
     51         endif
     52         call system("tmux load-buffer -", @a)
     53     finally
     54         @a = a_save
     55         set operatorfunc=
     56     endtry
     57 enddef
     58 
     59 def TmuxSendFileLocationNormal()
     60     call system($"tmux set-buffer {expand('%')}:{line(".")}")
     61     call system("tmux paste-buffer -p -t {marked}")
     62 enddef
     63 
     64 def TmuxSendFileLocationVisual()
     65     var first = min([line('v'), line('.')])
     66     var last = max([line('v'), line('.')])
     67     call system($"tmux set-buffer {expand('%')}:{first}-{last}")
     68     call system("tmux paste-buffer -p -t {marked}")
     69     call system("tmux select-pane -t {marked}")
     70 enddef
     71 
     72 nmap <silent> <localleader>tb <Cmd>set operatorfunc=<SID>TmuxSetBufferNormal<CR>g@
     73 vmap <silent> <localleader>tb <ScriptCmd>TmuxSetBufferVisual()<CR>
     74 nmap <silent> <localleader>ts <Cmd>set operatorfunc=<SID>TmuxSendKeysToMarkedNormal<CR>g@
     75 vmap <silent> <localleader>ts <ScriptCmd>TmuxSendKeysToMarkedVisual()<CR>
     76 
     77 map <silent> <localleader>te <ScriptCmd>system('tmux send-keys -t {marked} Enter')<CR>
     78 map <silent> <localleader>tc <ScriptCmd>system('tmux send-keys -t {marked} <C-c>')<CR>
     79 map <silent> <localleader>td <ScriptCmd>system('tmux send-keys -t {marked} <C-d>')<CR>
     80 
     81 nmap <silent> <localleader>tl <ScriptCmd>TmuxSendFileLocationNormal()<CR>
     82 vmap <silent> <localleader>tl <ScriptCmd>TmuxSendFileLocationVisual()<CR>
     83 
     84 # Python
     85 map <silent> <localleader>tpi <ScriptCmd>system('tmux send-keys -t {marked} python Enter')<CR>
     86 map <silent> <localleader>tpa <ScriptCmd>system('tmux send-keys -t {marked} ". venv/bin/activate"')<CR>
     87 
     88 # R
     89 map <silent> <localleader>tri <ScriptCmd>system('tmux send-keys -t {marked} R Enter')<CR>
     90 
     91 # vim: et sts=4 sw=4