Vim-go: how to disable gofmt in vim-plug/vim-go?

Created on 24 Jun 2016  路  2Comments  路  Source: fatih/vim-go

Actual behavior:

gofmt formats go source code. It adds 8-space tabs for indentation.

Write here what's happening:

Hello,
I'm using vim-plug as my vim based IDE for golang.
I've a very specific query. I don't want gofmt to do any unnecessary formatting for my code. I raised an issue with vim-plug but I was suggested to post an issue here.

I've my own "set tabstop=4" in my .vimrc.
I add header section to .go sources to help the reader understand what exactly the source file is all about. At many places in the code, additionally, I add more than 1 line in the code for cleaner segregation. Earlier, gofmt was modifying everything while saving a file.

By including following 2 lines in my .vimrc
let g:go_fmt_fail_silently = 1
let g:go_fmt_autosave = 0
I've gotten rid of unnecessary errors and formatting by gofmt to my .go source files, respectively.

However, I'm not being able to disable gofmt from adding 8-space tab. Since I have my own 4-space tab, I don't want those 8-charater tabs added by gofmt.

So, I want to disable gofmt at all.

Write here what you're expecting ...

  • Disabled gofmt

Configuration

Version information:
I use vim-7.4 on CentOS 7.2

Most helpful comment

Just to clarify, let g:go_fmt_autosave = 0 will stop vim-go from running gofmt on your source code, which is what you've already stated you have tried.

If you want to modify some of the behaviour of gofmt, see its arguments (run gofmt -help) and add any options you would like vim-go to execute by adding them to your vimrc using g:go_fmt_options, eg:

let g:go_fmt_options = "-tabwidth=4"

But I'm not certain if this is what you're asking, to disable gofmt, do exactly what you've done, add let g:go_fmt_autosave = 0 to your vimrc (be sure to close and reopen vim, or source it)

All 2 comments

Just to clarify, let g:go_fmt_autosave = 0 will stop vim-go from running gofmt on your source code, which is what you've already stated you have tried.

If you want to modify some of the behaviour of gofmt, see its arguments (run gofmt -help) and add any options you would like vim-go to execute by adding them to your vimrc using g:go_fmt_options, eg:

let g:go_fmt_options = "-tabwidth=4"

But I'm not certain if this is what you're asking, to disable gofmt, do exactly what you've done, add let g:go_fmt_autosave = 0 to your vimrc (be sure to close and reopen vim, or source it)

Hi @sameeroak

Add something like this to your vimrc to change how you want to represent a tab:

au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4

This is a vim issue. vim-go doesn't set anything to 8-space tab. It's your setting which you have to change. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

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

joeblubaugh picture joeblubaugh  路  3Comments

svanharmelen picture svanharmelen  路  3Comments

SirmaXX picture SirmaXX  路  3Comments

andrejvanderzee picture andrejvanderzee  路  3Comments