Skip to content

Commit c853343

Browse files
committed
Add an optional argument to RunVimTmuxCommand to stop sending a return after the command. Fixes #9
1 parent 06ba414 commit c853343

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

README.mkd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ Otherwise download the latest [tarball](https://github.com/benmills/vimux/tarbal
2222
## Usage
2323

2424
### RunVimTmuxCommand
25-
Run a system command in a small horizontal split bellow the current pane vim is in.
25+
Run a system command in a small horizontal split bellow the current pane vim is in. You can optionally pass a second argument to stop vimux from automatically sending a return after the command.
2626

2727
```viml
2828
" Run the current file with rspec
2929
map <Leader>rb :call RunVimTmuxCommand("clear; rspec " . bufname("%"))<CR>
30+
31+
" Run command without sending sending a return
32+
map <Leader>rq :call RunVimTmuxCommand("clear; rspec " . bufname("%"), 0)<CR>
3033
```
3134

3235
### PromptVimTmuxCommand
@@ -101,13 +104,13 @@ Here is how to use vimux to send code to a REPL. This is similar to tslime. Firs
101104
map <LocalLeader>vp :PromptVimTmuxCommand<CR>
102105
103106
" If text is selected, save it in the v buffer and send that buffer it to tmux
104-
vmap <LocalLeader>vs "vy :call RunVimTmuxCommand(@v)<CR>
107+
vmap <LocalLeader>vs "vy :call RunVimTmuxCommand(@v . "\n", 0)<CR>
105108
106109
" Select current paragraph and send it to tmux
107110
nmap <LocalLeader>vs vip<LocalLeader>vs<CR>
108111
```
109112

110-
Now, open a clojure file. Let's say your leader is backslash (\). Type \vp, and then type lein repl at the prompt. This opens a tmux split running a REPL. Then, select text or put the cursor on a function and type \vs. This will send it to the REPL and evaluate it.
113+
Now, open a clojure file. Let's say your leader is backslash (\). Type \vp, and then type lein repl at the prompt. This opens a tmux split running a REPL. Then, select text or put the cursor on a function and type \vs. This will send it to the REPL and evaluate it. The reason we pass `0` to `RunVimTmuxCommand` is to stop the normal return that is sent to the runner pane and use our own new line so the clojure REPL will evaluate the selected text without adding an extra return. Thanks to @trptcolin for discovering this issue.
111114

112115
## Options
113116

plugin/vimux.vim

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ command InspectVimTmuxRunner :call InspectVimTmuxRunner()
1414
command InterruptVimTmuxRunner :call InterruptVimTmuxRunner()
1515
command PromptVimTmuxCommand :call PromptVimTmuxCommand()
1616

17-
function RunVimTmuxCommand(command)
17+
function RunVimTmuxCommand(command, ...)
18+
let l:autoreturn = 1
19+
20+
if exists("a:1")
21+
let l:autoreturn = a:1
22+
endif
23+
1824
let g:_VimTmuxCmd = a:command
19-
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"))
25+
26+
if l:autoreturn == 1
27+
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"))
28+
else
29+
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"), false)
30+
endif
2031
endfunction
2132

2233
function RunLastVimTmuxCommand()
@@ -152,9 +163,9 @@ class TmuxSession
152163
_run("send-keys -t #{target(:pane => runner_pane)} ^c")
153164
end
154165

155-
def run_shell_command(command)
166+
def run_shell_command(command, auto_return = true)
156167
reset_shell
157-
_send_command(command, target(:pane => runner_pane))
168+
_send_command(command, target(:pane => runner_pane), auto_return)
158169
_move_up_pane
159170
end
160171

@@ -178,9 +189,9 @@ class TmuxSession
178189
_run("select-pane -t #{target}")
179190
end
180191

181-
def _send_command(command, target)
192+
def _send_command(command, target, auto_return = true)
182193
_run("send-keys -t #{target} \"#{command.gsub('"', '\"')}\"")
183-
_run("send-keys -t #{target} Enter")
194+
_run("send-keys -t #{target} Enter") if auto_return
184195
end
185196

186197
def _run(command)

0 commit comments

Comments
 (0)