Search code examples
vimgogofmt

disable gofmt in vim-plug in vim ide


How can i disable gofmt in vim-plug ide for vim?

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 on github but I was suggested that the issue is with vim-go.

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. Can someone please help me to disable gofmt?

Version information: I use vim-7.4 on CentOS 7.2

Regards, - sameer oak.


Solution

  • Instead of disabling gofmt, you could make it work how you expect. This answer about tabs/spaces will be useful.

    You need to set shiftwidth=4 so that tab indents appear to be the same size as tabs. There are no 8 space tabs vs 4 space tabs (tabs don't have a width, vim uses these setting to display the tab as 4 characters.

    You really should reconsider fighting against gofmt, It will make reading the code much easier for anyone with Go experience.