Comments (11)
That's up to the go fmt command, if you use gofmt
just specifiy in your vimrc:
let g:go_fmt_options = "-tabs=false -tabwidth=4"
from vim-go.
Hi,
It is possible to pass options to the formatter like so:
gofmt -tabs=false -tabwidth=4 main.go
Via the go-vim setting:
let g:go_fmt_command = "gofmt -tabs=false -tabwidth=4"
However now I'm wondering how would it be possible to pass these settings when using goimports
?
I'm trying to get my code formatted with spaces instead of tabs, 4 spaces in width.
from vim-go.
Well just pass it to goimports binary path!
let g:go_goimports_bin = "goimports -tabs=false -tabwidth=4"
can you try it?
from vim-go.
I have 2 issues with that approach.
1.) It doesn't work. I get this on save.
2.) It prompts me with goimports installation on every vim start, even though its already installed.
% vim main.go
Installing code.google.com/p/go.tools/cmd/goimports
Press ENTER or type command to continue
from vim-go.
My suggestion was based on that you had a goimports installed somewhere else. We need to seperate binary path and the options. I've opened a new issue where we are gonna introduce a new parameter. Let us talk from there now. Thanks for reporting.
from vim-go.
I see the commit 13a71b0 adds new option, but I'm wondering how can that option be used to achieve go-vim usage of goimports combined with custom formatting settings (-tabs=false -tabwidth=4
)?
from vim-go.
@fatih Well, naturally that's the first thing I tried before posting here, and it didn't work for me.
Is there any additional setting that I'm missing?
I went ahead, and deleted every occurrence of goimports from my system, and had the go-vim plugin re-install it.
sudo find / -name 'goimports'
The behavior is pretty much the same as with the one described 9 days ago. When I hit :w
, I get some echo of code on bottom, while in buffer the code is nor formatted, nor do imports run. link
Here is my current vimrc
from vim-go.
goimports
doesn't have those options. Only gofmt has it. You need to change it to g:go_fmt_command = 'gofmt'
.
from vim-go.
Well than, that means if I want to do goimports there is no way for me to format my code with proper spacing (other than running :%retab on BufWritePost)?
from vim-go.
Yes, unfortunately this is a limitation of goimports
rather than vim-go. You can just type goimports
in the shell and see what it supports.
from vim-go.
I was aware of this limitation, I thought that you would do some magic with new update (eg. run goimports first, and than gofmt over it).
The goimports tool is really stupid in this sense, they should merge it with gofmt and provide it as a flag.
from vim-go.
Related Issues (20)
- Vim jumps to end of file on save HOT 2
- GoSameIds end position miscalculated for identifiers at the end of line
- GoExtract sends incorrect location to LSP HOT 1
- Error detected while processing Buf WritePre HOT 1
- Error detected while processing function <SNR>129_debugasync: E117 Unknown function: state ... HOT 1
- Typecheck errors when calling a function in another go file in the same package. HOT 9
- Godef has been Invalid in code with "import C" HOT 4
- Merged #3617 breaks UltiSnips placeholder mechanism HOT 3
- Cannot install or make it work with NeoVim gives error E492: Not an editor command :GoDef HOT 2
- Auto imports not working HOT 1
- Error in identifier/syntax prevents autocommands to be executed HOT 7
- Support quoting arguments to :GoImpl HOT 3
- Development: `make lint` always fails using GNU grep 3.8 or later HOT 5
- Vim randomly stops when go_highlight_function_calls is on HOT 4
- Execution: GoFmt changes the Chinese at the end to <e4> HOT 2
- Startup time ~4 s on nvim, macos, even with empty init.lua HOT 1
- c-x c-o error HOT 8
- Running :GoDef or any other commands that require gopls fails without error HOT 9
- vim has defined a set of key positions that span the ages
- Thank you for sharing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-go.