Vim and Go setup

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.

Vi

Install vim-go: it comes with a massive set of tools.

goimports

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

Install: go install golang.org/x/lint/golint@latest

Run: golint ./...

Vi: :GoLint

SA with govet

Run: go vet ./...

Vi: :GoVet

This does not catch subtle bugs around shadow variables. So consider installing shadow as well:

Install: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest

Run: shadow ./...

Combine golint, govet with golangci-lint

This tool runs 10 different linters by default and support dozens others.

Install: see official docs

Run: golangci-lint run

vim-go notes

  • Code completion is with Ctrl-x Ctrl-o
  • :Tagbar is bound to F8
  • :GoDef is bound to gd
  • :GoDefStack shows you how deep you’ve jumped, GoDefPop or Ctrl-T just pops to the last hop

Sample makefile

.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

Books read in May

Assassin’s Apprentice by Robin Hobb

I wanted to read a good fantasy book and this was the one I picked. Very enjoyable read and seems worth committing to finish the trilogy.

The Pig That Wants to Be Eaten, by Julian Baggini

Fun armchair philosophy thought experiments. There are a hundred of them, from age old paradoxes (Zeno) to funny insights that trigger a deeper train of thought (Douglas Adams). The fact that there are so many make this book harder to read in one sitting. Good in bite-sized chunks.

Nexus, by Ramez Naam

Wanted a switch from fantasy to science fiction so I tried this one out. It was alright.

Books read in April

The Brain: The Story of You, by David Eagleman

Felt like a short read that didn’t go deep enough but this was a nice introduction to our current undertanding of how the brain functions. The author does a nice job of keep things interesting at a high level.

Golden Gate, by Vikram Seth

This is a technically brilliant book but ultimately dealt with themes outside my usual genres.

Haunted, by Chuck Palahniuk

Ahh this one is not for the queasy. A collection of uncomfortable short stories about cynical wannabe authors stuck in a writers’ retreat.