Vim: Replace vim-tbone with custom function

This commit is contained in:
Bill Niblock 2017-12-19 20:04:14 -05:00
parent 719ba0bb30
commit 1d04a4cc1d
2 changed files with 35 additions and 4 deletions

View file

@ -115,7 +115,10 @@ command! -nargs=1 -complete=help H :tabnew | :set buftype=help | :h <args>
nnoremap <silent> <leader>f :<C-u>edit ~/.dotfiles/<CR> nnoremap <silent> <leader>f :<C-u>edit ~/.dotfiles/<CR>
nnoremap <silent> <leader>F :<C-u>tabnew ~/.dotfiles/<CR> nnoremap <silent> <leader>F :<C-u>tabnew ~/.dotfiles/<CR>
" Emulate vim-vinegar " Emulate vim-vinegar
nnoremap <silent> - :silent edit <C-R>=empty(expand('%')) ? '.' : expand('%:p:h')<CR><CR> nnoremap <silent> - :silent edit <C-R>=empty(expand('%')) ? '.' :
\ expand('%:p:h')<CR><CR>
" Send the select range to the specified pane
command! -nargs=? -range Twrite execute TmuxWrite(<q-args>, <line1>, <line2>)
" Some notes/wiki shortcuts " Some notes/wiki shortcuts
nnoremap <silent> <leader>ww :<C-u>edit ~/Documents/Wiki/index.md<CR> nnoremap <silent> <leader>ww :<C-u>edit ~/Documents/Wiki/index.md<CR>
nnoremap <silent> <leader>ws :<C-u>vsplit ~/Documents/Wiki/scratchpad.md<CR> nnoremap <silent> <leader>ws :<C-u>vsplit ~/Documents/Wiki/scratchpad.md<CR>
@ -127,8 +130,8 @@ nnoremap <silent> <leader>tj :call NewJournal()<CR>
" ============================================================================== " ==============================================================================
" Read from the journal template, and replace 'Date' with today's date " Read from the journal template, and replace 'Date' with today's date
function! NewJournal() abort function! NewJournal() abort
.-1read ~/.vim/templates/journal .-1read ~/.vim/templates/journal
s/Date/\=strftime("%A, %B %d")/ s/Date/\=strftime("%A, %B %d")/
endfunction endfunction
" Fetch the git branch of the current file, if applicable " Fetch the git branch of the current file, if applicable
function! GitBranch() abort function! GitBranch() abort
@ -136,6 +139,35 @@ function! GitBranch() abort
\ | tr -d '\n'") \ | tr -d '\n'")
return strlen(l:branchname) > 0 ? '#'.l:branchname : '' return strlen(l:branchname) > 0 ? '#'.l:branchname : ''
endfunction 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 " Plugins
" ============================================================================== " ==============================================================================

View file

@ -17,5 +17,4 @@ call plug#begin('~/.vim/bundle')
Plug 'sheerun/vim-polyglot' Plug 'sheerun/vim-polyglot'
Plug 'junegunn/goyo.vim' Plug 'junegunn/goyo.vim'
Plug 'tpope/vim-tbone'
call plug#end() call plug#end()