They also make it easy to write more modest programs such as IDE plugins, for instance. All these items build on each other, making the Go environment more productive by automating many tasks.
╰─○ ls -a | grep .vimrc
.vimrc
.vimrc.before
.vimrc.before.local ←
.vimrc.bundles
.vimrc.bundles.local
.vimrc.local ←
Either copy my files to $HOME adding a dot `.` before the name or if you already use
spf13 append the content to your config files.
Install vim-go
Update spf13's bundles (aka vim plugins):
# precondition: spf13 go bundle group should have been enabled in
# .vimrc.before.local (done in my custom config file) in the previous step.
vim +BundleInstall! +BundleClean +q
# check out the install worked as expected
ls -l .vim/bundle | grep vim-go
drwxr-xr-x 17 gonzalo staff 578 oct 26 22:49 vim-go
of public names: exported functions, interfaces or structs from imported packages, or public struct methods.
hint: type ctrl + space over a function to see its definition
code navigation
Navigate to definitions like a boss, even to the standard lib.
hint: i have 2 maps: <C-]> to navigate in current buffer and <C-a> to navigate in a new tab
:GoTest, :GoTestCompile
Test you package, compile your test after refactor.
:GoDoc
If you just need the documentation of the element over the cursor, type :GoDoc command.
snippets :clock1:
spf13 comes with the neocomplcache snippets plugin. Type the following characters, select the snippet and press <C-k> to go to the next step of the snippet.
Shows an arbitrary path from the root of the call graph to the function containing the selection
:GoDescribe
Shows various properties: syntactic kind, type of an expression, value of a constant expression, the size, alignment, method set, and interfaces of a type, the declaration of an identifier...
:GoVet: runs vet to spot errors not detected by the compiler.
:GoMetalinter: runs both previous linters and some more.
Gometalinter :hammer: 1/2
gofmt, govet, golint ✔
gotype: syntactic and semantic analysis similar to the Go compiler.
deadcode: finds unused code.
gocyclo: computes the cyclomatic complexity of functions.
goimports: checks missing or unreferenced package imports.
Gometalinter :hammer: 2/2
varcheck: find unused global variables and constants.
structcheck: find unused struct fields.
aligncheck: warn about un-optimally aligned structures.
errcheck: check that error return values are used.
dupl: reports potentially duplicated code.
ineffassign: detect when assignments to existing variables are not used.
interfacer: suggest narrower interfaces
config tips :page_with_curl:
let g:go_fmt_fail_silently = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_interfaces = 1
let g:go_term_enabled = 1
" let g:go_metalinter_autosave = 1
" autoimport ftw
let g:go_fmt_command = "goimports"
" go-def
au FileType go nmap (go-def)
au FileType go nmap (go-def-tab)
" default: ['vet', 'golint', 'errcheck']
" gotype does not work with non-installed packages https://github.com/alecthomas/gometalinter/issues/40
let g:go_metalinter_deadline = '20s'
let g:go_metalinter_enabled = ['golint', 'vetshadow', 'errcheck', 'ineffassign', 'vet', 'goimports', 'defercheck', 'aligncheck', 'dupl', 'gofmt', 'varcheck', 'gocyclo', 'testify', 'structcheck', 'deadcode']