Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
111 lines
3.2 KiB
Markdown
111 lines
3.2 KiB
Markdown
---
|
||
title: "SpaceVim lang#go 模块"
|
||
description: "这一模块为 SpaceVim 提供了 Go 的开发支持,包括代码补全、语法检查、代码格式化等特性。"
|
||
lang: zh
|
||
---
|
||
|
||
# [可用模块](../../) >> lang#go
|
||
|
||
<!-- vim-markdown-toc GFM -->
|
||
|
||
- [模块简介](#模块简介)
|
||
- [功能特性](#功能特性)
|
||
- [启用模块](#启用模块)
|
||
- [模块选项](#模块选项)
|
||
- [快捷键](#快捷键)
|
||
|
||
<!-- vim-markdown-toc -->
|
||
|
||
## 模块简介
|
||
|
||
该模块为 SpaceVim 提供了 [Golang](https://go.dev/) 开发支持,包括代码补全,格式化,语法检查等特性。同时提供诸多语言专属快捷键。
|
||
|
||
## 功能特性
|
||
|
||
- 代码补全
|
||
- 语法检查
|
||
- 跳转定义处
|
||
- 查询函数引用
|
||
|
||
## 启用模块
|
||
|
||
可通过在配置文件内加入如下配置来启用该模块:
|
||
|
||
```toml
|
||
[[layers]]
|
||
name = "lang#go"
|
||
```
|
||
|
||
默认情况下,tagbar 这一插件无法显示 go 语法树,需要安装一个依赖 [gotags](https://github.com/jstemmer/gotags):
|
||
|
||
```sh
|
||
go get -u github.com/jstemmer/gotags
|
||
```
|
||
|
||
## 模块选项
|
||
|
||
- `enabled_linters`: 设置 Golang 语言的语法检查的工具列表,默认模式值是`['golint']`。
|
||
可用的值包括:`go`, `gometalinter`
|
||
- `go_file_head`: 设置默认的 Golang 源文件头模板。
|
||
|
||
```
|
||
[[layers]]
|
||
name = "lang#go"
|
||
go_file_head = [
|
||
'#!/usr/bin/python3',
|
||
'# -*- coding : utf-8 -*-'
|
||
''
|
||
]
|
||
```
|
||
|
||
- `go_interpreter`: 设置 Golang 的可执行文件路径。
|
||
|
||
```
|
||
[[layers]]
|
||
name = 'lang#go'
|
||
go_interpreter = '~/download/bin/go'
|
||
```
|
||
|
||
- `format_on_save`: 设置是否启用 Golang 源文件保存时的语法检查,默认该选项已禁用。
|
||
|
||
```
|
||
[[layers]]
|
||
name = 'lang#go'
|
||
format_on_save = true
|
||
```
|
||
|
||
## 快捷键
|
||
|
||
**语言专属快捷键:**
|
||
|
||
| 快捷键 | 功能描述 |
|
||
| --------- | ------------------------- |
|
||
| `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 |
|
||
| `SPC l m` | format improts |
|
||
| `SPC l M` | add import |
|
||
| `SPC l r` | go run |
|
||
| `SPC l s` | fill struct |
|
||
| `SPC l t` | go test |
|
||
| `SPC l v` | freevars |
|
||
| `SPC l x` | go referrers |
|
||
|
||
**代码格式化:**
|
||
|
||
默认的代码格式化快捷键是 `SPC b f`,该快捷键由 `format` 模块定义,同时也可以通过 `g =` 来对齐整个文档。
|
||
|
||
为了使得 `format` 模块支持 Go 文件,需要确认有可执行命令 [go-fmt](http://golang.org/cmd/gofmt/) 或者 [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports),
|
||
通常 `go-fmt` 命令为 Go 自带的程序,请确认 Go 开发环境是否配置正确。
|