diff --git a/plugin/vimux.vim b/plugin/vimux.vim index e25ca66..0236bd7 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -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" @@ -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