diff --git a/vim/vimrc b/vim/vimrc index 4314a1f..787e567 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -115,7 +115,10 @@ command! -nargs=1 -complete=help H :tabnew | :set buftype=help | :h nnoremap f :edit ~/.dotfiles/ nnoremap F :tabnew ~/.dotfiles/ " Emulate vim-vinegar -nnoremap - :silent edit =empty(expand('%')) ? '.' : expand('%:p:h') +nnoremap - :silent edit =empty(expand('%')) ? '.' : + \ expand('%:p:h') +" Send the select range to the specified pane +command! -nargs=? -range Twrite execute TmuxWrite(, , ) " Some notes/wiki shortcuts nnoremap ww :edit ~/Documents/Wiki/index.md nnoremap ws :vsplit ~/Documents/Wiki/scratchpad.md @@ -127,8 +130,8 @@ nnoremap tj :call NewJournal() " ============================================================================== " Read from the journal template, and replace 'Date' with today's date function! NewJournal() abort - .-1read ~/.vim/templates/journal - s/Date/\=strftime("%A, %B %d")/ + .-1read ~/.vim/templates/journal + s/Date/\=strftime("%A, %B %d")/ endfunction " Fetch the git branch of the current file, if applicable function! GitBranch() abort @@ -136,6 +139,35 @@ function! GitBranch() abort \ | tr -d '\n'") return strlen(l:branchname) > 0 ? '#'.l:branchname : '' endfunction +" Simple tmux send-keys functionality +function! TmuxWrite(pane, line1, line2) abort + let l:val = join(filter(map(getline(a:line1, a:line2), + \ 'substitute(v:val, "^\\s*", "", "")'), + \ "!empty(v:val)"), + \ "\r") + try + if empty(a:pane) + throw 'Twrite Failed: No pane provided' + endif + let l:panes = systemlist('tmux list-panes -t '.a:pane.' -F "#D + \ #{pane_active}"') + let l:target = substitute( + \join(filter(l:panes, 'match(v:val, ''%\d 1'') == 0'), ""), + \'\(%\d\) 1', '\1', "") + if l:target ==# $TMUX_PANE + throw 'Twrite Failed: Not writing self' + endif + let l:out = system('tmux send-keys -t'.l:target.' "" ' + \.shellescape(l:val)) + if v:shell_error + throw 'Twrite Failed: '.l:out[0:-2] + endif + echo len(l:val).' keys sent to '.a:pane + return '' + catch /.*/ + return 'echoerr '.string(v:exception) + endtry +endfunction " ============================================================================== " Plugins " ============================================================================== diff --git a/vim/vimrc-plugins b/vim/vimrc-plugins index fe18bab..d0e9dcb 100644 --- a/vim/vimrc-plugins +++ b/vim/vimrc-plugins @@ -17,5 +17,4 @@ call plug#begin('~/.vim/bundle') Plug 'sheerun/vim-polyglot' Plug 'junegunn/goyo.vim' - Plug 'tpope/vim-tbone' call plug#end()