preservim / vimux

easily interact with tmux from vim
MIT License
2.2k stars 159 forks source link

Vimux always uses nearest Tmux pane instead of creating its own. #103

Closed g-rutter closed 9 years ago

g-rutter commented 10 years ago

The docs say that setting

let VimuxUseNearestPane = 0

Will force vimux to create its own pane for running my commands, instead of putting them in an existing nearby Tmux pane. In my experience, this has no effect. The only way I can get vimux to create its own pane is by having no other panes open for use.

g-rutter commented 10 years ago

I can't get it to work on either a Mac system or a SUSE system, although they are sharing a common .vimrc, .tmuxrc, and similar .profile/.bashrcs, so it could be some incompatible setting. Will update with any further findings, of course.

g-rutter commented 10 years ago

Tried blanking out all three of these files and it didn't help. Out of ideas for the moment.

yunake commented 10 years ago

I suspect that what you put here is what you have in the config, which is wrong. it should be let g:VimuxUseNearestPane = 0, not let VimuxUseNearestPane = 0. Does this solve your problem?

g-rutter commented 10 years ago

Thanks for your suggestion. I've tried this both ways and it doesn't help.

yunake commented 10 years ago

hmmm. are you using the latest git source? are you using panes or windows (output of :echo _VimuxRunnerType()). can you please open fresh tmux window, fresh vim, and show the output of :echo g:VimuxUseNearest, :echo _VimuxNearestIndex(), :echo g:VimuxRunnerIndex, :echo _VimuxHasRunner(g:VimuxRunnerIndex), and tmux list-windows -a && tmux list-panes -a from shell in this tmux session; then execute :call VimuxOpenRunner(), then do the last three echos and the shell command again and show their new results. Then open a new tmux window, new vim, in that window open new pane (or a new nearby window if you use windows), and repeat all the steps and echos, post the results.

yunake commented 10 years ago

you should also try my fork, it uses IDs instead of indexes of reference tmux objects, perhaps that's your problem (although as far as I can tell the code in this repo should work too)

sitaktif commented 9 years ago

@g-rutter The documentation mentions g:VimuxUseNearest but not g:VimuxUseNearestPane.

Starting a new tmux session, running vim, creating a tmux split pane, focusing Vim back, calling :let g:VimuxUseNearest = 0, then calling :call VimuxRunCommand("echo 42") does create a third pane (omitting the reset of g:VimuxUseNearest, the command would instead be run on the pane I have created and not create a third one).

Can you please try to reproduce and potentially close the bug?

g-rutter commented 9 years ago

Yes, that fixes it. Looks like the docs have been updated.

alexzanderr commented 3 years ago

does work for me with let g:VimuxUseNearest = 0

my vimux config:

let g:VimuxHeight = "50"
let g:VimuxOrientation = "h"
let g:VimuxOpenExtraArgs = "-b"
let g:VimuxUseNearest = 0

let g:VimuxCloseOnExit = 1
let g:VimuxPromptString = "enter command for tmux splitted pane: "
let g:VimuxRunnerName = "vscode-code-runner"
alexzanderr commented 3 years ago

you should also try my fork, it uses IDs instead of indexes of reference tmux objects, perhaps that's your problem (although as far as I can tell the code in this repo should work too)

your fork doesnt even work with all the standard vimux configs...

the same config file i used for the other repo of vimux (which works like a charm) doesnt work with your "forked" repo

my vimux config:


let g:VimuxHeight = "50"
let g:VimuxOrientation = "h"
let g:VimuxOpenExtraArgs = "-b"
let g:VimuxUseNearest = 0

let g:VimuxCloseOnExit = 1
let g:VimuxPromptString = "enter command for tmux splitted pane: "
let g:VimuxRunnerName = "vscode-code-runner"

" just like vs code runner

function! s:code_runner(below)
    if a:below == 1
        let g:VimuxOrientation = "v"
        let g:VimuxOpenExtraArgs = ""
    endif

    if &modified == 1
        w!
    endif 

    if &filetype == "python"
        call VimuxRunCommand("python3 " . bufname("%"))

    elseif &filetype == "javascript"
        call VimuxRunCommand("node " . bufname("%"))

    elseif &filetype == "go"
        call VimuxRunCommand("go run " . bufname("%"))

    elseif &filetype == "cpp"
        let filename = split(bufname("%"), "\\V.")[0]
        call VimuxRunCommand("g++ " . bufname("%") . " -o " . filename . " && ./" . filename)

    elseif &filetype == "c"
        let filename = split(bufname("%"), "\\V.")[0]
        call VimuxRunCommand("gcc " . bufname("%") . " -o " . filename . " && ./" . filename)

    elseif &filetype == "html"
        let g:VimuxOrientation = "v"
        let g:VimuxOpenExtraArgs = ""
        let g:VimuxHeight = "7"

        call VimuxRunCommand("live-server " . bufname("%"))
    endif

    let g:VimuxHeight = "20"
    let g:VimuxOrientation = "h"
    let g:VimuxOpenExtraArgs = "-b"
endfunction

" code runner orientation to the left side
nnoremap <silent> <C-A-n> :call <SID>code_runner(0)<CR>
inoremap <silent> <C-A-n> <C-o>:call <SID>code_runner(0)<CR>

" code runner orientation below
nnoremap <silent> <C-A-b> :call <SID>code_runner(1)<CR>
inoremap <silent> <C-A-b> <C-o>:call <SID>code_runner(1)<CR>

function! s:pytest_compilation()
    if &modified == 1
        w!
    endif 
    if &filetype == "python"
        call VimuxRunCommand("pytest -vv " . getcwd() . "/" . expand('%:f'))
    else
        echo "wrong filetype"
    endif

endfunction

nnoremap <silent> <C-A-m> :call <SID>pytest_compilation()<CR>
inoremap <silent> <C-A-m> <C-o>:call <SID>pytest_compilation()<CR>

nnoremap <silent> <C-A-c> :VimuxClearTerminalScreen<CR>
inoremap <silent> <C-A-c> <C-o>:VimuxClearTerminalScreen<CR>