1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 20:10:05 +08:00
SpaceVim/docs/layers/lang/go.md

113 lines
3.1 KiB
Markdown
Raw Normal View History

---
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
<!-- 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)
- [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.
## 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
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
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
- reference finder
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
```
## Key bindings
**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 |
| `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 |
| `SPC l x` | go referrers |
**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: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.