https://github.com/fatih/vim-go
It's an extremely well made vim plugin. You can use it with the new neovim lsp client. It's not a new neovim only plugin so there are alternatives, but none seem quite as polished yet:
https://github.com/ray-x/go.nvim https://github.com/nvim-treesitter/nvim-treesitter
format with go-fumpt
gofumpt is a stricter version of gofmt. It generally looks better and removes some pointless whitespace.
let g:go_fmt_command="gopls"
let g:go_gopls_gofumpt=1
testing
<leader>tt
tests the whole project or <leader>tf
tests the function under
your cursor.
metalinter
<leader>tm
or :GoMetaLinter
runs a bunch of nice go linters on your project
and shows the issues in a quickfix list.
implements
Make your type implement an interface. Place your cursor on the type and run:
:GoImpl io.ReadWriteCloser
or without needing to put your cursor on your type:
:GoImpl b *B fmt.Stringer
coverage
<leader>tc
to toggle coverage or run the commands manually.
:GoCoverage
:GoCoverageClear
extract function
Select a region in visual mode and run :GoFreevars
. The result contains all
the variables that are free variables. You can use that information to refactor
that block of code out into it's own function.
snippets
errp
if err != nil {
panic()
}
fn -> fmt.Println()
ff -> fmt.Printf()
ln -> log.Println()
lf -> log.Printf()