From 42217e1600313b046505164edb0060830a2bea85 Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Fri, 23 Nov 2012 00:33:07 -0500 Subject: [PATCH] Add KillRunner and FocusRunner commands --- README.mkd | 6 ++++++ plugin/vim-tmux-runner.vim | 35 +++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.mkd b/README.mkd index 7f8444e..7fe42d8 100644 --- a/README.mkd +++ b/README.mkd @@ -6,6 +6,12 @@ A simple, vimscript only, command runner for sending commands from vim to tmux This plugin exposes a command to open a small command runner window +- Open runner window +- Automatic cd to project root (via git cdup) +- Send command (with escaping, auto-enter, auto-pre-clear) +- Enter tmux-copy mode in pane +- Maximize the runner pane + ## Inspiration - Tslime.vim diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim index ceb4f6a..60cd880 100644 --- a/plugin/vim-tmux-runner.vim +++ b/plugin/vim-tmux-runner.vim @@ -17,23 +17,42 @@ function! s:initVariable(var, value) endfunction function! s:OpenRunnerPane() - call s:CacheVimTmuxPane() + let s:cached_vim_pane = s:ActiveTmuxPaneNumber() call system("tmux split-window -p 20 -v") - call s:RefocusVimPane() + let s:cached_runner_pane = s:ActiveTmuxPaneNumber() + call s:FocusTmuxPane(s:cached_vim_pane) endfunction -function! s:CacheVimTmuxPane() +function! s:KillRunnerPane() + call system("tmux kill-pane -t " . s:cached_runner_pane) + unlet s:cached_runner_pane +endfunction + +function! s:ActiveTmuxPaneNumber() let panes = system("tmux list-panes") for pane_title in split(panes, '\n') if pane_title =~ '\(active\)' - let s:cached_vim_pane = pane_title[0] - echo s:cached_vim_pane + return pane_title[0] endif endfor endfunction -function! s:RefocusVimPane() - call system("tmux select-pane -t " . s:cached_vim_pane) +function! s:TmuxPanes() + let panes = system("tmux list-panes") + return split(panes, '\n') endfunction -command! VimTmuxRunnerOpenRunner :call s:OpenRunnerPane() +function! s:FocusTmuxPane(pane_number) + call system("tmux select-pane -t " . a:pane_number) +endfunction + +function! s:FocusRunnerPane() + call s:FocusTmuxPane(s:cached_runner_pane) +endfunction + +command! VTROpenRunner :call s:OpenRunnerPane() +command! VTRKillRunner :call s:KillRunnerPane() +command! VTRFocusRunnerPane :call s:FocusRunnerPane() +nmap ,vm :VTROpenRunner +nmap ,kv :VTRKillRunner +nmap ,fp :VTRFocusRunnerPane