Vim-go: Calling :GoRun multiple times results in multiple panes

Created on 23 Sep 2019  路  11Comments  路  Source: fatih/vim-go

What did you do? (required: The issue will be closed when not provided)

When I call :GoRun, it opens a pane where the result of the execution is displayed. If I call the command again, an additional pane opens to display the output.

What did you expect to happen?

I expected that the output pane would be reused for each subsequent execution.

What happened instead?

After calling :GoRun a few times, I have to close each of the panes that has been opened.

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc

set runtimepath^=~/.vim runtimepath+=~/.vim/after
set backspace=indent,start
let &packpath = &runtimepath
filetype plugin indent on
set autowrite

call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()

Vim version (first three lines from :version):

NVIM v0.4.2
Build type: Release
LuaJIT 2.0.5

Go version (go version):


go version go1.13 darwin/amd64

Go environment

go env Output:


GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ctrom/Library/Caches/go-build"
GOENV="/Users/ctrom/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ctrom/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j7/ntkq2mqs2c9bjqjsq118vt9w4yq__w/T/go-build264463625=/tmp/go-build -gno-record-gcc-switches -fno-common"

feature

Most helpful comment

Probably not the cleaner solution but it works for me:

function! ReuseVimGoTerm(cmd) abort
    for w in nvim_list_wins()
        if "goterm" == nvim_buf_get_option(nvim_win_get_buf(w), 'filetype')
            call nvim_win_close(w, v:true)
            break
        endif
    endfor
    execute a:cmd
endfunction

let g:go_term_enabled = 1
let g:go_term_mode = "silent keepalt rightbelow 15 split"
let g:go_def_reuse_buffer = 1

autocmd FileType go nmap <leader>r :call ReuseVimGoTerm('GoRun')<Return>

All 11 comments

With the vimrc that you provided, :GoRun should not be running in a separate window at all. Do you have g:go_term_enabled set?

@bhcleek here is a screenshot of what I see after a single :GoRun execution:
Screen Shot 2019-09-23 at 10 22 42
Here's one after a second execution:
Screen Shot 2019-09-23 at 10 24 26

I have not made any config changes beyond what is visible in the vimrc I posted.

Sorry about the confusion; I was mis-remembering how g:go_term_enabled is used.

You're right, it doesn't re-use the terminal window. But I'm not sure if it _should_ 馃

How do you envision the workflow? Having to close the pane after every run (or multiple panes after every few runs) doesn't seem ideal to me.

It's a fair question. But let's turn it on its head: let's say you run :GoRun in multiple packages. What do you think the behavior should be?

What's the use case for overwriting a :GoRun terminal window? With things being async, would it make sense to overwrite an existing terminal window?

I would also like to have an option to be able to reuse the terminal. I think it should be safe if the process is over, otherwise you could get confising output, but if its implemented as an optional flag, I dont see any problems

this happens to me also. The most common use case is that I am writing and compiling a single file. Re-using the output pane saves me continually closing it.

Does anyone have a workaround so that :GoRun reuses the same pane?

Probably not the cleaner solution but it works for me:

function! ReuseVimGoTerm(cmd) abort
    for w in nvim_list_wins()
        if "goterm" == nvim_buf_get_option(nvim_win_get_buf(w), 'filetype')
            call nvim_win_close(w, v:true)
            break
        endif
    endfor
    execute a:cmd
endfunction

let g:go_term_enabled = 1
let g:go_term_mode = "silent keepalt rightbelow 15 split"
let g:go_def_reuse_buffer = 1

autocmd FileType go nmap <leader>r :call ReuseVimGoTerm('GoRun')<Return>

Probably not the cleaner solution but it works for me:

function! ReuseVimGoTerm(cmd) abort
    for w in nvim_list_wins()
        if "goterm" == nvim_buf_get_option(nvim_win_get_buf(w), 'filetype')
            call nvim_win_close(w, v:true)
            break
        endif
    endfor
    execute a:cmd
endfunction

let g:go_term_enabled = 1
let g:go_term_mode = "silent keepalt rightbelow 15 split"
let g:go_def_reuse_buffer = 1

autocmd FileType go nmap <leader>r :call ReuseVimGoTerm('GoRun')<Return>

This is a great solution and it works for me.
Also with adding a new line, this function satisfy another requirement, to close the window quickly.

" Close the GoRun window
autocmd FileType go nmap <leader>r :call ReuseVimGoTerm('')<Return>

@pwntester thanks for that, it's a great solution and works like a charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SirmaXX picture SirmaXX  路  3Comments

preslavmihaylov picture preslavmihaylov  路  3Comments

korjavin picture korjavin  路  4Comments

groob picture groob  路  3Comments

Michael-F-Ellis picture Michael-F-Ellis  路  3Comments