I’m reading Learning Go by Jon Bodner. The opening chapters have some nice tips on getting a good developer environment. Vim has the excellent vim-go plugin that bundles a ton of nice stuff. Here are some notes I took while I got things setup.
My .vimrc is here.
My detailed notes from reading the book are here, and what follows below is just the subset that deals with dev environment.
Install vim-go: it comes with a massive set of tools.
goimports for some neat stuff that gofmt doesn’t do. Install with:
go install golang.org/x/tools/cmd/goimports@latest
And run with:
goimports -l -w .
Vi: Just save it.
Linting with golint
go install golang.org/x/lint/golint@latest
SA with govet
go vet ./...
This does not catch subtle bugs around shadow variables. So consider installing
shadow as well:
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
Combine golint, govet with golangci-lint
This tool runs 10 different linters by default and support dozens others.
Install: see official docs
- Code completion is with
:Tagbaris bound to
:GoDefis bound to
GoDefStackshows you how deep you’ve jumped,
Ctrl-Tjust pops to the last hop
.DEFAULT_GOAL := build fmt: go fmt ./... .PHONY:fmt lint: fmt golint ./... .PHONY:lint vet: fmt go vet ./... shadow ./... .PHONY:vet build: vet go build hello.go .PHONY:build