Vim-go: setting go_fmt_command="goimports" doesn't seem to work

Created on 3 Jul 2015  ·  8Comments  ·  Source: fatih/vim-go

I have the following settings in my vimrc

" vim-go
let g:go_fmt_command = "goimports"
let g:go_fmt_autosave = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1

When I save go fmt is run by it doesn't appear to be using goimports for formatting. I have to manually run :GoImports each time.

Most helpful comment

I confirm GoImports doesn't work in Neovim when saving a file. I don't have that issue in Vim. GoImports works automatically when saving a file in Vim. However in Neovim nothing happens when saving. I don't think it is a conflicting path. I checked my GOPATH and GOROOT and they're configured properly.

All 8 comments

Hi @gregf. I don't know how this is possible, the only option would be that goimports is not installed. This feature is working because I'm using it myself and there are no recent changes on this particular feature.

To install goimports please run :GoInstallBinaries or invoke go get golang.org/x/tools/cmd/goimports from your terminal. Let me know how it works for you. Cheers.

I did what you said, but it's still not working.

which goimports
/home/gregf/code/go/bin/goimports
echo $GOPATH
/home/gregf/code/go

I'm a idiot I had a conflicting setting in another file. Sorry to waste your time.

No worries, I'm happy it worked out for you. The thing is I'm receiving a lot of issues like this and I don't know how to deal with them anymore :) Need a way to filter it out but when I close it directly it feels like I'm a rude person or arrogant (which I try to avoid at all). So anyway, again happy that it worked out for you. Happy vim-go coding!

@gregf any chance to recall which was the conflicting setting… I'd like to save @fatih from another stupid issue. 🦍

Btw this is my .vimrc excerpt:

all plug#begin()
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
call plug#end()

set number
set autowrite

let mapleader = ","

"execute pathogen#infect()
"syntax on
"filetype plugin indent on

"------------GO Lang Customizations
let g:go_highlight_types = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:go_fmt_command = "goimports"
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
autocmd FileType go nmap <leader>t <Plug>(go-test)
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
  let l:file = expand('%')
  if l:file =~# '^\f\+_test\.go$'
    call go#test#Test(0, 1)
  elseif l:file =~# '^\f\+\.go$'
    call go#cmd#Build(0)
  endif
endfunction
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>c <Plug>(go-coverage-toggle)

Fixed!… sorry for the wasting time!

iirc it was just a conflicting go path some where else in my .zshrc or something like that. It's been to long to remember for sure though.

I confirm GoImports doesn't work in Neovim when saving a file. I don't have that issue in Vim. GoImports works automatically when saving a file in Vim. However in Neovim nothing happens when saving. I don't think it is a conflicting path. I checked my GOPATH and GOROOT and they're configured properly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surest picture surest  ·  3Comments

mnarrell picture mnarrell  ·  3Comments

svanharmelen picture svanharmelen  ·  3Comments

johnzeng picture johnzeng  ·  3Comments

danielmanesku picture danielmanesku  ·  4Comments