Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
" ----------------------------------------------------------------------------
" tmux
" ----------------------------------------------------------------------------
" Recommended
let mapleader = ' '
function! s:tmux_send(content, dest) range
let dest = empty(a:dest) ? input('To which pane? ') : a:dest
let tempfile = tempname()
call writefile(split(a:content, "\n", 1), tempfile, 'b')
call system(printf('tmux load-buffer -b vim-tmux %s \; paste-buffer -d -b vim-tmux -t %s',
\ shellescape(tempfile), shellescape(dest)))
call delete(tempfile)
endfunction
function! s:tmux_map(key, dest)
execute printf('nnoremap <silent> %s "tyy:call <SID>tmux_send(@t, "%s")<cr>', a:key, a:dest)
execute printf('xnoremap <silent> %s "ty:call <SID>tmux_send(@t, "%s")<cr>gv', a:key, a:dest)
endfunction
call s:tmux_map('<leader>tt', '')
call s:tmux_map('<leader>th', '.left')
call s:tmux_map('<leader>tj', '.bottom')
call s:tmux_map('<leader>tk', '.top')
call s:tmux_map('<leader>tl', '.right')
call s:tmux_map('<leader>ty', '.top-left')
call s:tmux_map('<leader>to', '.top-right')
call s:tmux_map('<leader>tn', '.bottom-left')
call s:tmux_map('<leader>t.', '.bottom-right')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment