Vim-go: "vim-go: goimports does not support srcdir" and file clearing

Created on 25 Mar 2016  路  7Comments  路  Source: fatih/vim-go

Actual behavior

When GoImports is set to run when the file is saved (or perhaps more accurately, when GoFmt is run), vim-go complains with the following: "vim-go: goimports does not support srcdir." and the file is cleared and overwritten.

I have run :GoUpdateBinaries, but the problem persists.

Expected behavior

GoImports would function normally without the error message, or at least not clear the file when it fails.

Steps to reproduce:

  1. Add let g:go_fmt_command = "goimports" to your .vimrc so that GoImports is triggered on save.
  2. Open any Go file
  3. Run :w

    Configuration

  • vimrc you used to reproduce
syntax on
call pathogen#infect()
call pathogen#helptags()

" vim-go configuration
let g:go_fmt_command = "goimports"
  • vim version: 7.4
  • vim-go version: tip
  • go version: go1.6 linux/amd64

Most helpful comment

I ran into this problem, too. My issue was apparently that $GOPATH/bin was not in PATH. (How vim-go managed to find a version of goimport, however outdated, I'm not sure.) Once I set export PATH=$PATH:$GOPATH/bin in .bashrc, everything worked fine.

All 7 comments

Hi @velovix

What happens if you run goimports --help from the terminal? I think it seems like you still have the old one. In the flags you should see the -srcdir flag, if that is not the case, you still have the old one.

Results of goimports --help:

$ goimports --help
usage: goimports [flags] [path ...]
  -d    display diffs instead of rewriting files
  -e    report all errors (not just the first 10 on different lines)
  -l    list files whose formatting differs from goimport's
  -srcdir dir
        choose imports as if source code is from dir
  -w    write result to (source) file instead of stdout

It looks like I'm up to date.

What gives this ex command when you execute it from inside vim:

:echo system("goimports --help")
:echo system("which goimports")

And from your terminal:

which goimports

Seems like your Vim picks up an old version somehow. This is not something I can reproduce, let's see if we can find something.

It looks like this wasn't an issue with vim-go after all. I found that any echo system() command would print nothing, so after some messing around, I decided to reinstall vim and now everything seems to be working fine again. I have no idea what happened, but I suspect that while I was experimenting with neovim, I must have messed up something. I can't seem to reproduce it, though. Thanks for working this through with me and sorry for the noise!

I just had the same issue and was able to reproduce it. The symptom happens when I am using tmux.
OS: mac os x El Capitan

I ran into this problem, too. My issue was apparently that $GOPATH/bin was not in PATH. (How vim-go managed to find a version of goimport, however outdated, I'm not sure.) Once I set export PATH=$PATH:$GOPATH/bin in .bashrc, everything worked fine.

I ran into this issue as well, but was able to fix it by running :GoUpdateBinaries

Was this page helpful?
0 / 5 - 0 ratings

Related issues

preslavmihaylov picture preslavmihaylov  路  3Comments

orlangure picture orlangure  路  3Comments

cassiobotaro picture cassiobotaro  路  3Comments

smontazeran picture smontazeran  路  4Comments

danielmanesku picture danielmanesku  路  4Comments