2017-12-19 09:31:58 +08:00
---
title: "SpaceVim golang layer"
description: "This layer is for golang development. It also provides additional language-specific key mappings."
---
2018-06-23 14:37:41 +08:00
# [Available Layers](../../) >> lang#go
2017-12-19 09:31:58 +08:00
<!-- vim - markdown - toc GFM -->
- [Description ](#description )
- [Install ](#install )
2018-01-03 22:56:15 +08:00
- [Features ](#features )
2022-05-27 11:48:19 +08:00
- [Layer options ](#layer-options )
2017-12-19 09:31:58 +08:00
- [Key bindings ](#key-bindings )
<!-- vim - markdown - toc -->
## Description
2022-05-27 11:48:19 +08:00
This layer is for [golang ](https://go.dev/ ) development. It also provides additional language-specific key mappings.
2017-12-19 09:31:58 +08:00
## Install
2021-06-21 20:39:29 +08:00
To use this configuration layer, update your custom configuration file with:
2018-06-23 14:37:41 +08:00
```toml
[[layers]]
name = "lang#go"
```
2018-01-03 22:56:15 +08:00
2019-03-18 07:45:39 +08:00
After the installation, run `:GoInstallBinaries` inside vim.
2019-05-08 09:29:54 +08:00
To enable tagbar support, you need to install [gotags ](https://github.com/jstemmer/gotags ):
```sh
2021-10-01 14:30:03 +08:00
go install github.com/jstemmer/gotags@latest
2019-05-08 09:29:54 +08:00
```
2018-01-03 22:56:15 +08:00
## Features
- auto-completion
- syntax checking
- goto definition
2021-09-02 13:37:12 +08:00
- reference finder
2017-12-19 09:31:58 +08:00
2022-05-27 11:48:19 +08:00
## Layer options
1. `enabled_linters` : set a list of enabled lint for golang. by default this
option is `['golint']` . The available linters includes: `go` , `gometalinter`
2. go_file_head: the default file head for golang source code.
```
[layers]
name = "lang#go"
go_file_head = [
'#!/usr/bin/python3',
'# -*- coding : utf-8 -*-'
''
]
```
3. `go_interpreter` : Set the interpreter of go.
```
[[layers]]
name = 'lang#go'
go_interpreter = '~/download/bin/go'
```
4. 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
```
2017-12-19 09:31:58 +08:00
## Key bindings
2017-12-19 16:23:46 +08:00
**Import key bindings:**
2019-02-03 20:51:01 +08:00
| Key Bindings | Descriptions |
| ------------ | ------------------------- |
| `SPC l a` | go alternate |
| `SPC l b` | go build |
| `SPC l c` | go coverage |
| `SPC l d` | go doc |
| `SPC l D` | go doc vertical |
| `SPC l e` | go rename |
| `SPC l g` | go definition |
| `SPC l G` | go generate |
| `SPC l h` | go info |
| `SPC l i` | go implements |
| `SPC l I` | implement stubs |
| `SPC l k` | add tags |
| `SPC l K` | remove tags |
| `SPC l l` | list declarations in file |
2019-12-31 17:19:57 +08:00
| `SPC l m` | format imports |
2019-02-03 20:51:01 +08:00
| `SPC l M` | add import |
2019-07-19 12:46:07 +08:00
| `SPC l r` | go run |
2019-02-03 20:51:01 +08:00
| `SPC l s` | fill struct |
| `SPC l t` | go test |
| `SPC l v` | freevars |
2019-07-19 12:46:07 +08:00
| `SPC l x` | go referrers |
2017-12-19 16:23:46 +08:00
**Code formatting:**
2022-05-27 11:48:19 +08:00
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.
2017-12-19 16:23:46 +08:00
2017-12-19 16:42:29 +08:00
To make neoformat support go files, you should have [go-fmt ](http://golang.org/cmd/gofmt/ ) command available, or
install [goimports ](https://godoc.org/golang.org/x/tools/cmd/goimports ). `go-fmt` is delivered by golang's default installation, so make sure you have correctly setup your go environment.