Back to Spacevim

SpaceVim golang layer

docs/layers/lang/go.md

2.4.03.5 KB
Original Source

Available Layers >> lang#go

<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc -->

Description

This layer is for golang development. It also provides additional language-specific key mappings.

Features

  • auto-completion
  • syntax checking
  • goto definition
  • reference finder

Install

To use this configuration layer, update your custom configuration file with:

toml
[[layers]]
  name = "lang#go"

After the installation, run :GoInstallBinaries inside vim.

To enable tagbar support, you need to install gotags:

sh
go install github.com/jstemmer/gotags@latest

Layer options

  • enabled_linters: set a list of enabled lint for golang. by default this option is ['golint']. The available linters includes: go, gometalinter

  • go_file_head: the default file head for golang source code.

    [[layers]]
        name = "lang#go"
        go_file_head = [
            '#!/usr/bin/python3',
            '# -*- coding : utf-8 -*-'
            ''
    ]
    
  • go_interpreter: Set the interpreter of go.

    [[layers]]
        name = 'lang#go'
        go_interpreter = '~/download/bin/go'
    
  • format_on_save: enable/disable code formation when save go file. This options is disabled by default, to enable it:

    [[layers]]
        name = 'lang#go'
        format_on_save = true
    

Key bindings

Import key bindings:

Key BindingsDescriptions
SPC l ago alternate
SPC l bgo build
SPC l cgo coverage
SPC l dgo doc
SPC l Dgo doc vertical
SPC l ego rename
SPC l ggo definition
SPC l Ggo generate
SPC l hgo info
SPC l igo implements
SPC l Iimplement stubs
SPC l kadd tags
SPC l Kremove tags
SPC l llist declarations, need ctrlp or fzf layer
SPC l mformat imports
SPC l Madd import
SPC l rgo run
SPC l sfill struct
SPC l tgo test
SPC l vfreevars
SPC l xgo referrers

Code formatting:

the default key bindings for formatting current buffer is SPC b f, and this key bindings is defined in format layer. You can also use g= to indent current buffer.

To make neoformat support go files, you should have go-fmt command available, or install goimports. go-fmt is delivered by golang's default installation, so make sure you have correctly setup your go environment.