Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Vimux to add option 'VimuxUseLast' #143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vimux

## begin fork notes
### Feature: VimuxUseLast
`let g:VimuxUseLast = 1` => when choosing vimux runner pane, use last active tmux pane
## end fork notes
Easily interact with tmux from vim.

![vimux](https://www.braintreepayments.com/assets/images/blog/vimux3.png)
Expand Down
29 changes: 27 additions & 2 deletions plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ endfunction

function! VimuxOpenRunner()
let nearestIndex = _VimuxNearestIndex()
let lastIndex = _VimuxLastIndex()

if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
if _VimuxOption("g:VimuxUseLast", 1) == 1 && lastIndex != -1
let g:VimuxRunnerIndex = lastIndex
elseif _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex
else
if _VimuxRunnerType() == "pane"
Expand Down Expand Up @@ -182,6 +185,28 @@ function! _VimuxNearestIndex()
return -1
endfunction

function! _VimuxLastIndex()

let currentID = _VimuxTmuxPaneIndex()

call _VimuxTmux("last-pane")
let lastID = _VimuxTmuxPaneIndex()
call _VimuxTmux("last-pane")

if currentID != lastID
if _VimuxRunnerType() == "window"
return lastID
elseif _VimuxRunnerType() == "pane"
if split(currentID, "\\.")[0] == split(lastID, "\\.")[0]
return lastID
endif
endif
endif

return -1

endfunction

function! _VimuxRunnerType()
return _VimuxOption("g:VimuxRunnerType", "pane")
endfunction
Expand All @@ -199,5 +224,5 @@ function! _VimuxTmuxProperty(property)
endfunction

function! _VimuxHasRunner(index)
return match(_VimuxTmux("list-"._VimuxRunnerType()."s -a"), a:index.":")
return match(_VimuxTmux("list-"._VimuxRunnerType()."s -a"), _VimuxTmuxSession().":".a:index.":")
endfunction