Skip to content

Commit f0bdd95

Browse files
committed
Merge pull request #11 from oscardelben/master
Use existing pane if one is found
2 parents d75780a + 4f90d43 commit f0bdd95

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.mkd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,13 @@ Set the default position of the runner pane.
131131
```viml
132132
let VimuxOrientation = "h"
133133
```
134+
135+
### VimuxUseNearestPane
136+
Use nearest pane (not used by vim) if found instead of running
137+
split-window.
138+
Useful if you always have two panes opened and you want Vimux to use the
139+
existing one.
140+
141+
```viml
142+
let VimuxUseNearestPane = 1
143+
```

doc/vimux.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The percent of the screen the split pane Vimux will spawn should take up.
3737
Default: "20"
3838

3939
------------------------------------------------------------------------------
40-
2.2 g:VimuxOrientation *VimuxConfiguration_oriengation*
40+
2.2 g:VimuxOrientation *VimuxConfiguration_orientation*
4141

4242
The default orientation of the split tmux pane. This tells tmux to make the
4343
pane either vertically or horizontally, which is backward from how Vim handles
@@ -50,3 +50,12 @@ Options:
5050
"h": horizontal
5151

5252
Default: "v"
53+
54+
------------------------------------------------------------------------------
55+
2.3 g:VimuxUseNearestPane *VimuxConfiguration_use_nearest_pane*
56+
57+
Use exising pane (not used by vim) if found instead of running split-window.
58+
59+
let VimuxUseNearestPane = 1
60+
61+
Default: 0

plugin/vimux.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ class TmuxSession
130130
def runner_pane
131131
if @runner_pane.nil?
132132
type = Vim.evaluate('exists("g:_VimTmuxInspecting")') != 0
133-
_run("split-window -p #{height} #{orientation}")
133+
use_nearest_pane = Vim.evaluate('exists("g:VimuxUseNearestPane")') != 0
134+
if use_nearest_pane && nearest_inactive_pane_id
135+
_run("select-pane -t #{target(:pane => nearest_inactive_pane_id)}")
136+
else
137+
_run("split-window -p #{height} #{orientation}")
138+
end
134139
@runner_pane = active_pane_id
135140
Vim.command("let g:_VimTmuxRunnerPane = '#{@runner_pane}'")
136141
end
@@ -162,6 +167,12 @@ class TmuxSession
162167
end
163168
end
164169

170+
def nearest_inactive_pane_id
171+
panes = _run("list-pane").split("\n")
172+
pane = panes.find { |p| p !~ /active/ }
173+
pane ? pane.split(':').first : nil
174+
end
175+
165176
def _move_up_pane
166177
_run("select-pane -t #{target}")
167178
end

0 commit comments

Comments
 (0)