Vim-go: using `:GoDef` failed

Created on 22 Apr 2018  路  5Comments  路  Source: fatih/vim-go

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

using :GoDef failed, and the :message shows:

"~/go/src/zhaofang_API/src/main.go" 18L, 457C
vim-go: searching declaration ...
vim-go: FAILED
vim-go: executing job failed: No such file or directory
vim-go: /Users/casa/go/src/zhaofang_API

What did you expect to happen?

jump to the definition

What happened instead?

using :GoDef but failed, and the :message shows:

"~/go/src/zhaofang_API/src/main.go" 18L, 457C
vim-go: searching declaration ...
vim-go: FAILED
vim-go: executing job failed: No such file or directory
vim-go: /Users/casa/go/src/zhaofang_API

Configuration (MUST fill this out):

  • vim-go version:

latest in master branch: 7491209072ed4aa746e6fe7894f976ecd251801e

  • vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):
set nocompatible              " be iMproved, required

if has("syntax")
  syntax on
endif

if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

filetype off                  " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'gmarik/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'mattn/emmet-vim'
Plugin 'posva/vim-vue'
Plugin 'othree/html5.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tpope/vim-commentary'
Plugin 'vim-scripts/a.vim'
Plugin 'godlygeek/tabular'
Plugin 'tpope/vim-surround'
Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled=1
let g:vim_markdown_no_default_key_mappings=1
set nofoldenable

" Plugin 'vim-scripts/taglist.vim'
" let Tlist_Show_One_File=1
" let Tlist_Ctags_Cmd='/usr/local/bin/ctags'

Plugin 'majutsushi/tagbar'
let g:tagbar_autofocus = 1
let g:tagbar_ctags_bin = '/usr/local/bin/ctags'
let g:tagbar_autofocus = 1
let g:tagbar_show_linenumbers = 1
" let g:tagbar_autoshowtag = 1
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }

Plugin 'Lokaltog/vim-easymotion'
let g:EasyMotion_leader_key='f'

Plugin 'fatih/vim-go'
let g:go_highlight_types = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
" let g:go_highlight_fields = 1
" let g:go_highlight_extra_types = 1
" let g:go_highlight_build_constraints = 1

Plugin 'Valloric/YouCompleteMe'
let g:ycm_autoclose_preview_window_after_insertion = 1

call vundle#end()
filetype plugin indent on
syntax on
filetype on

set shiftwidth=4
set tabstop=4
set softtabstop=4

set ambiwidth=double
set autoread
set autoindent
set autowrite
set backspace=indent,eol,start
set cscopetag
set expandtab
set encoding=utf-8
set hidden             " Hide buffers when they are abandoned
set hlsearch
set ignorecase      " Do case insensitive matching
set incsearch
set lbr
set nu
set showcmd     " Show (partial) command in status line.
set showmatch       " Show matching brackets.
set smarttab
set smartcase       " Do smart case matching

set timeout ttimeoutlen=100 timeoutlen=5000

let mapleader=';'
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
au FileType go nmap <leader>d :GoDoc<CR>
au FileType go nmap <c-]> gd
au FileType go set shiftwidth=4
au FileType go set tabstop=4
au FileType go set softtabstop=4
au FileType go set expandtab
au FileType go nmap <leader>f :GoTestFunc<CR>
au FileType go nmap <leader>d :GoDoc<CR>

  • Vim version (first three lines from :version):

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 22 2018 09:58:11)
macOS version 10.13.4
Included patches: 1-1633

  • Go version (go version):
    go version go1.10.1 darwin/amd64

  • Go environment (go env):
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/casa/Library/Caches/go-build"
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/casa/go"
    GORACE=""
    GOROOT="/usr/local/Cellar/go/1.10.1/libexec"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.10.1/libexec/pkg/tool/darwin_amd64"
    GCCGO="gccgo"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    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/vq/f6l9s55s3ddfh6c2zw7qspkc0000gn/T/go-build286151148=/tmp/go-build -gno-record-gcc-switches -fno-common"

Most helpful comment

I just had the same problem.
I fixed it by adding go bin directory to $PATH: export PATH=$PATH:$HOME/Dev/go/bin
Make sure you execute first: :GoUpdateBinaries

All 5 comments

I just had the same problem.
I fixed it by adding go bin directory to $PATH: export PATH=$PATH:$HOME/Dev/go/bin
Make sure you execute first: :GoUpdateBinaries

Thanks! Your answer works! @sabala12

Just be careful and don't use ~ in the path to go/bin.

Wrong way: export PATH=$PATH:~/path/to/go/bin
Right way: export PATH=$PATH:$HOME/path/to/go/bin

Not work for me.
.zshrc :

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MacVim.app/Contents/bin/:/Users/fanux/go/bin:/Users/fanux/go/bin:/Users/fanux/work/bin
export GOPATH=/Users/fanux/work
export GOROOT=/Users/fanux/go

macvim

already :GoUpdateBinaries

I can access self defined package, but cannot access go standard package, I guess something is wrong with my GOROOT. I set GOROOT, it works.

export GOROOT=/usr/local/Cellar/go/1.10.8/libexec/go
Was this page helpful?
0 / 5 - 0 ratings

Related issues

derekchiang picture derekchiang  路  3Comments

zhangjing picture zhangjing  路  3Comments

smontazeran picture smontazeran  路  4Comments

danielmanesku picture danielmanesku  路  4Comments

andrejvanderzee picture andrejvanderzee  路  3Comments