Add SendSelected and SendLine commands
These commands allow for arbitrary text in the Vim buffer to be passed to the runner pane for execution.
This commit is contained in:
parent
00b5ae4e40
commit
fc3acbaded
@ -8,18 +8,18 @@ CONTENTS *vtr-contents*
|
|||||||
|
|
||||||
1. About............................ |VTR-About|
|
1. About............................ |VTR-About|
|
||||||
2. Usage ........................... |VTR-Usage|
|
2. Usage ........................... |VTR-Usage|
|
||||||
2.1 ................................ |VtrOpenRunner|
|
2.1 ............................... |VtrSendCommandToRunner|
|
||||||
2.2 ................................ |VtrKillRunner|
|
2.2 ............................... |VtrSendLineToRunner|
|
||||||
2.1 ................................ |VtrSendCommandToRunner|
|
2.3 ............................... |VtrSendSelectedToRunner|
|
||||||
2.2 ................................ |VtrOpenRunner|
|
2.4 ............................... |VtrOpenRunner|
|
||||||
2.3 ................................ |VtrKillRunner|
|
2.5 ............................... |VtrKillRunner|
|
||||||
2.4 ................................ |VtrFocusRunner|
|
2.6 ............................... |VtrFocusRunner|
|
||||||
2.5 ................................ |VtrResizeRunner|
|
2.7 ............................... |VtrResizeRunner|
|
||||||
2.6 ................................ |VtrReorientRunner|
|
2.8 ............................... |VtrReorientRunner|
|
||||||
2.7 ................................ |VtrDetachRunner|
|
2.9 ............................... |VtrDetachRunner|
|
||||||
2.8 ................................ |VtrReattachRunner|
|
2.10 ............................... |VtrReattachRunner|
|
||||||
2.9 ................................ |VtrClearRunner|
|
2.11 ............................... |VtrClearRunner|
|
||||||
2.10 ............................... |VtrFlushCommand|
|
2.12 ............................... |VtrFlushCommand|
|
||||||
3. Configuration ................... |VTR-Configuration|
|
3. Configuration ................... |VTR-Configuration|
|
||||||
3.1 ................................ |VtrPercentage|
|
3.1 ................................ |VtrPercentage|
|
||||||
3.2 ................................ |VtrOrientation|
|
3.2 ................................ |VtrOrientation|
|
||||||
@ -88,9 +88,21 @@ setting. The command is then stored in an internal variable and will
|
|||||||
continue to be used for subsequent calls to the command. The stored command
|
continue to be used for subsequent calls to the command. The stored command
|
||||||
can be cleared using |VtrFlushCommand|.
|
can be cleared using |VtrFlushCommand|.
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*VtrSendLineToRunner*
|
||||||
|
2.2 VtrSendLineToRunner~
|
||||||
|
|
||||||
|
Send the current line to the runner pane for execution.
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*VtrSendSelectedToRunner*
|
||||||
|
2.3 VtrSendSelectedToRunner~
|
||||||
|
|
||||||
|
Send the current visual selection to the runner pane for execution.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrOpenRunner*
|
*VtrOpenRunner*
|
||||||
2.2 VtrOpenRunner~
|
2.4 VtrOpenRunner~
|
||||||
|
|
||||||
Open a tmux pane, referred to as the "runner", adjacent to the tmux pane
|
Open a tmux pane, referred to as the "runner", adjacent to the tmux pane
|
||||||
containing the current vim session. This command will make use of the
|
containing the current vim session. This command will make use of the
|
||||||
@ -99,7 +111,7 @@ restore a detached pane or create a new one as needed.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrKillRunner*
|
*VtrKillRunner*
|
||||||
2.3 VtrKillRunner~
|
2.5 VtrKillRunner~
|
||||||
|
|
||||||
Kill the tmux runner pane. this pane will kill either the local or detached
|
Kill the tmux runner pane. this pane will kill either the local or detached
|
||||||
runner pane. this command does nothing if there is currently not a runner
|
runner pane. this command does nothing if there is currently not a runner
|
||||||
@ -107,7 +119,7 @@ pane.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrFocusRunner*
|
*VtrFocusRunner*
|
||||||
2.4 VtrFocusRunner~
|
2.6 VtrFocusRunner~
|
||||||
|
|
||||||
Move the cursor to the runner to interact directly with it. A new runner will
|
Move the cursor to the runner to interact directly with it. A new runner will
|
||||||
be created if one does not exist and a detached pane will be restored as
|
be created if one does not exist and a detached pane will be restored as
|
||||||
@ -115,7 +127,7 @@ needed.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrResizeRunner*
|
*VtrResizeRunner*
|
||||||
2.5 VtrResizeRunner~
|
2.7 VtrResizeRunner~
|
||||||
|
|
||||||
Prompt for a new percentage then resize the runner pane to that percentage.
|
Prompt for a new percentage then resize the runner pane to that percentage.
|
||||||
This command will update the |VtrPercentage| setting for the current vim
|
This command will update the |VtrPercentage| setting for the current vim
|
||||||
@ -125,7 +137,7 @@ with the |VtrClearOnResize| setting.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrReorientRunner*
|
*VtrReorientRunner*
|
||||||
2.6 VtrReorientRunner~
|
2.8 VtrReorientRunner~
|
||||||
|
|
||||||
Switch the runner pane from its current orientation to the alternate
|
Switch the runner pane from its current orientation to the alternate
|
||||||
orientation (horizontal or vertical). The |VtrPercentage| will be maintained
|
orientation (horizontal or vertical). The |VtrPercentage| will be maintained
|
||||||
@ -135,7 +147,7 @@ setting.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrDetachRunner*
|
*VtrDetachRunner*
|
||||||
2.7 VtrDetachRunner~
|
2.9 VtrDetachRunner~
|
||||||
|
|
||||||
Detach the runner pane to its own window while keeping the cursor focus on the
|
Detach the runner pane to its own window while keeping the cursor focus on the
|
||||||
vim window. This command is useful if there are details in the runner pane or
|
vim window. This command is useful if there are details in the runner pane or
|
||||||
@ -148,7 +160,7 @@ needed again. The runner can later be restored with any of |VtrReattachRunner|,
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrReattachRunner*
|
*VtrReattachRunner*
|
||||||
2.8 VtrReattachRunner~
|
2.10 VtrReattachRunner~
|
||||||
|
|
||||||
Reattach the runner pane. This command assumes that the runner has previously
|
Reattach the runner pane. This command assumes that the runner has previously
|
||||||
been dismissed using the |VtrDetachRunner| command. The pane will be restored
|
been dismissed using the |VtrDetachRunner| command. The pane will be restored
|
||||||
@ -158,7 +170,7 @@ behavior can be disabled using the |VtrClearOnReattach| setting.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrClearRunner*
|
*VtrClearRunner*
|
||||||
2.9 VtrClearRunner~
|
2.11 VtrClearRunner~
|
||||||
|
|
||||||
Send the key sequence defined by the |VtrClearSequence| setting to the runner.
|
Send the key sequence defined by the |VtrClearSequence| setting to the runner.
|
||||||
By default this will clear any unfinished commands at the shell prompt and
|
By default this will clear any unfinished commands at the shell prompt and
|
||||||
@ -166,7 +178,7 @@ move the prompt up to hide any previous command output.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*VtrFlushCommand*
|
*VtrFlushCommand*
|
||||||
2.10 VtrFlushCommand~
|
2.12 VtrFlushCommand~
|
||||||
|
|
||||||
Flush the previous run command variable. After running this command, the next
|
Flush the previous run command variable. After running this command, the next
|
||||||
run of |VtrSendCommandToRunner| will again prompt for the command to run.
|
run of |VtrSendCommandToRunner| will again prompt for the command to run.
|
||||||
@ -262,20 +274,28 @@ following to your vimrc:
|
|||||||
|
|
||||||
let g:VtrUseVtrMaps = 1
|
let g:VtrUseVtrMaps = 1
|
||||||
|
|
||||||
The map set provided by VTR is:
|
The following normal mode maps are provided when g:VtrUseVtrMaps is set to 1:
|
||||||
|
|
||||||
Mapping | Command
|
Mapping | Command
|
||||||
-----------------------------
|
-----------------------------
|
||||||
<leader>rr | VtrResizeRunner
|
<leader>rr | VtrResizeRunner<cr>
|
||||||
<leader>ror | VtrReorientRunner
|
<leader>ror | VtrReorientRunner<cr>
|
||||||
<leader>sc | VtrSendCommandToRunner
|
<leader>sc | VtrSendCommandToRunner<cr>
|
||||||
<leader>or | VtrOpenRunner
|
<leader>sl | VtrSendLineToRunner<cr>
|
||||||
<leader>kr | VtrKillRunner
|
<leader>or | VtrOpenRunner<cr>
|
||||||
<leader>fr | VtrFocusRunner
|
<leader>kr | VtrKillRunner<cr>
|
||||||
<leader>dr | VtrDetachRunner
|
<leader>fr | VtrFocusRunner<cr>
|
||||||
<leader>ar | VtrReattachRunner
|
<leader>dr | VtrDetachRunner<cr>
|
||||||
<leader>cr | VtrClearRunner
|
<leader>ar | VtrReattachRunner<cr>
|
||||||
<leader>fc | VtrFlushCommand
|
<leader>cr | VtrClearRunner<cr>
|
||||||
|
<leader>fc | VtrFlushCommand<cr>
|
||||||
|
|
||||||
|
In addition, a single visual mode map is provided to send a visually selected
|
||||||
|
region to the runner pane:
|
||||||
|
|
||||||
|
Mapping | Command
|
||||||
|
-----------------------------
|
||||||
|
<leader>sv | VtrSendSelectedToRunner<cr>
|
||||||
|
|
||||||
Default: 0
|
Default: 0
|
||||||
|
|
||||||
|
@ -301,6 +301,36 @@ function! s:EnsureRunnerPane()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" From http://stackoverflow.com/q/1533565/
|
||||||
|
" 'how-to-get-visually-selected-text-in-vimscript'
|
||||||
|
function! s:GetVisualSelection()
|
||||||
|
normal! gv
|
||||||
|
let [lnum1, col1] = getpos("'<")[1:2]
|
||||||
|
let [lnum2, col2] = getpos("'>")[1:2]
|
||||||
|
let lines = getline(lnum1, lnum2)
|
||||||
|
let lines[-1] = lines[-1][: col2 - 2]
|
||||||
|
let lines[0] = lines[0][col1 - 1:]
|
||||||
|
return join(lines, "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendLineToRunner()
|
||||||
|
let line = getline('.')
|
||||||
|
call s:SendTextToRunner(line)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendSelectedToRunner()
|
||||||
|
let selected_text = s:GetVisualSelection()
|
||||||
|
call s:SendTextToRunner(selected_text)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:SendTextToRunner(text)
|
||||||
|
let escaped_text = substitute(a:text, "'", "'\\\\''", 'g')
|
||||||
|
call s:SendTmuxCommand(join(["set-buffer", "'" . escaped_text . "'"]))
|
||||||
|
let targeted_cmd = s:TargetedTmuxCommand("paste-buffer", s:runner_pane)
|
||||||
|
call s:SendTmuxCommand(targeted_cmd)
|
||||||
|
call s:SendEnterSequence()
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! VtrSendCommand(command)
|
function! VtrSendCommand(command)
|
||||||
call s:EnsureRunnerPane()
|
call s:EnsureRunnerPane()
|
||||||
let escaped_command = shellescape(a:command)
|
let escaped_command = shellescape(a:command)
|
||||||
@ -310,14 +340,16 @@ endfunction
|
|||||||
function! s:DefineCommands()
|
function! s:DefineCommands()
|
||||||
command! -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner(<f-args>)
|
command! -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner(<f-args>)
|
||||||
command! -nargs=? VtrResizeRunner call s:ResizeRunnerPane(<args>)
|
command! -nargs=? VtrResizeRunner call s:ResizeRunnerPane(<args>)
|
||||||
command! VtrOpenRunner :call s:EnsureRunnerPane()
|
command! VtrSendSelectedToRunner call s:SendSelectedToRunner()
|
||||||
command! VtrKillRunner :call s:KillRunnerPane()
|
command! VtrSendLineToRunner call s:SendLineToRunner()
|
||||||
command! VtrFocusRunner :call s:FocusRunnerPane()
|
command! VtrOpenRunner call s:EnsureRunnerPane()
|
||||||
command! VtrReorientRunner :call s:ReorientRunner()
|
command! VtrKillRunner call s:KillRunnerPane()
|
||||||
command! VtrDetachRunner :call s:DetachRunnerPane()
|
command! VtrFocusRunner call s:FocusRunnerPane()
|
||||||
command! VtrReattachRunner :call s:ReattachPane()
|
command! VtrReorientRunner call s:ReorientRunner()
|
||||||
command! VtrClearRunner :call s:SendClearSequence()
|
command! VtrDetachRunner call s:DetachRunnerPane()
|
||||||
command! VtrFlushCommand :call s:FlushCommand()
|
command! VtrReattachRunner call s:ReattachPane()
|
||||||
|
command! VtrClearRunner call s:SendClearSequence()
|
||||||
|
command! VtrFlushCommand call s:FlushCommand()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:DefineKeymaps()
|
function! s:DefineKeymaps()
|
||||||
@ -325,6 +357,8 @@ function! s:DefineKeymaps()
|
|||||||
nmap ,rr :VtrResizeRunner<cr>
|
nmap ,rr :VtrResizeRunner<cr>
|
||||||
nmap ,ror :VtrReorientRunner<cr>
|
nmap ,ror :VtrReorientRunner<cr>
|
||||||
nmap ,sc :VtrSendCommandToRunner<cr>
|
nmap ,sc :VtrSendCommandToRunner<cr>
|
||||||
|
nmap ,sl :VtrSendLineToRunner<cr>
|
||||||
|
vmap ,sv <Esc>:VtrSendSelectedToRunner<cr>
|
||||||
nmap ,or :VtrOpenRunner<cr>
|
nmap ,or :VtrOpenRunner<cr>
|
||||||
nmap ,kr :VtrKillRunner<cr>
|
nmap ,kr :VtrKillRunner<cr>
|
||||||
nmap ,fr :VtrFocusRunner<cr>
|
nmap ,fr :VtrFocusRunner<cr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user