mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:30:04 +08:00
Add go post (#2429)
This commit is contained in:
parent
728472c80a
commit
db55d72e76
@ -13,6 +13,8 @@
|
|||||||
"wiki/cn/Following-HEAD.md": {"alternate": "wiki/en/Following-HEAD.md"},
|
"wiki/cn/Following-HEAD.md": {"alternate": "wiki/en/Following-HEAD.md"},
|
||||||
"docs/_posts/2017-02-11-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2018-09-19-use-vim-as-a-java-ide.md"},
|
"docs/_posts/2017-02-11-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2018-09-19-use-vim-as-a-java-ide.md"},
|
||||||
"docs/_posts/2018-09-19-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2017-02-11-use-vim-as-a-java-ide.md"},
|
"docs/_posts/2018-09-19-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2017-02-11-use-vim-as-a-java-ide.md"},
|
||||||
|
"docs/_posts/2019-01-08-use-vim-as-a-go-ide.md": {"alternate": "docs/_posts/2019-01-07-use-vim-as-a-go-ide.md"},
|
||||||
|
"docs/_posts/2019-01-07-use-vim-as-a-go-ide.md": {"alternate": "docs/_posts/2019-01-08-use-vim-as-a-go-ide.md"},
|
||||||
"docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md"},
|
"docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md"},
|
||||||
"docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md"},
|
"docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md"},
|
||||||
"docs/_posts/2018-09-27-use-vim-as-a-python-ide.md": {"alternate": "docs/_posts/2018-09-28-use-vim-as-a-python-ide.md"},
|
"docs/_posts/2018-09-27-use-vim-as-a-python-ide.md": {"alternate": "docs/_posts/2018-09-28-use-vim-as-a-python-ide.md"},
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
" normal SPC l L list declarations in dir
|
" normal SPC l L list declarations in dir
|
||||||
" normal SPC l m format improts
|
" normal SPC l m format improts
|
||||||
" normal SPC l M add import
|
" normal SPC l M add import
|
||||||
" normal SPC l r go referrers
|
" normal SPC l x go referrers
|
||||||
" normal SPC l s fill struct
|
" normal SPC l s fill struct
|
||||||
" normal SPC l t go test
|
" normal SPC l t go test
|
||||||
" normal SPC l v freevars
|
" normal SPC l v freevars
|
||||||
" normal SPC l x go run
|
" normal SPC l r go run
|
||||||
" <
|
" <
|
||||||
|
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ function! s:language_specified_mappings() abort
|
|||||||
\ '<Plug>(go-build)',
|
\ '<Plug>(go-build)',
|
||||||
\ 'go build', 0)
|
\ 'go build', 0)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','c'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','c'],
|
||||||
\ '<Plug>(go-coverage)',
|
\ 'GoCoverageToggle',
|
||||||
\ 'go coverage', 0)
|
\ 'go coverage toggle', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','d'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','d'],
|
||||||
\ '<Plug>(go-doc)',
|
\ '<Plug>(go-doc)',
|
||||||
\ 'go doc', 0)
|
\ 'go doc', 0)
|
||||||
@ -128,17 +128,20 @@ function! s:language_specified_mappings() abort
|
|||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','M'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','M'],
|
||||||
\ ':GoImport ',
|
\ ':GoImport ',
|
||||||
\ 'add import', 0)
|
\ 'add import', 0)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','x'],
|
||||||
\ ':GoReferrers',
|
\ ':GoReferrers',
|
||||||
\ 'go referrers', 1)
|
\ 'go referrers', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','s'],
|
||||||
\ ':GoFillStruct',
|
\ ':GoFillStruct',
|
||||||
\ 'fill struct', 1)
|
\ 'fill struct', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','t'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','t'],
|
||||||
\ '<Plug>(go-test)',
|
\ 'GoTest',
|
||||||
\ 'go test', 0)
|
\ 'go test', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','T'],
|
||||||
|
\ 'GoTestFunc',
|
||||||
|
\ 'go test function', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','v'],
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','v'],
|
||||||
\ ':GoFreevars',
|
\ ':GoFreevars',
|
||||||
\ 'freevars', 1)
|
\ 'freevars', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','x'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -1139,11 +1139,11 @@ MAPPINGS
|
|||||||
normal SPC l L list declarations in dir
|
normal SPC l L list declarations in dir
|
||||||
normal SPC l m format improts
|
normal SPC l m format improts
|
||||||
normal SPC l M add import
|
normal SPC l M add import
|
||||||
normal SPC l r go referrers
|
normal SPC l x go referrers
|
||||||
normal SPC l s fill struct
|
normal SPC l s fill struct
|
||||||
normal SPC l t go test
|
normal SPC l t go test
|
||||||
normal SPC l v freevars
|
normal SPC l v freevars
|
||||||
normal SPC l x go run
|
normal SPC l r go run
|
||||||
<
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
105
docs/_posts/2019-01-07-use-vim-as-a-go-ide.md
Normal file
105
docs/_posts/2019-01-07-use-vim-as-a-go-ide.md
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
---
|
||||||
|
title: "Use Vim as a Go IDE"
|
||||||
|
categories: [tutorials, blog]
|
||||||
|
images: https://user-images.githubusercontent.com/13142418/57321608-4a484880-7134-11e9-8e43-5fa05085d7e5.png
|
||||||
|
excerpt: "A general guide for using SpaceVim as Go IDE, including layer configuration, requiems installation and usage."
|
||||||
|
type: BlogPosting
|
||||||
|
comments: true
|
||||||
|
commentsID: "Use Vim as a Go IDE"
|
||||||
|
---
|
||||||
|
|
||||||
|
# [Blogs](../blog/) >> Use Vim as a Go IDE
|
||||||
|
|
||||||
|
This is a general guide for using SpaceVim as a Go IDE, including layer configuration and usage.
|
||||||
|
Each of the following sections will be covered:
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc GFM -->
|
||||||
|
|
||||||
|
- [Enable language layer](#enable-language-layer)
|
||||||
|
- [code completion](#code-completion)
|
||||||
|
- [alternate file jumping](#alternate-file-jumping)
|
||||||
|
- [code running](#code-running)
|
||||||
|
- [project building](#project-building)
|
||||||
|
- [run test](#run-test)
|
||||||
|
- [code coverage](#code-coverage)
|
||||||
|
- [code format](#code-format)
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
|
### Enable language layer
|
||||||
|
|
||||||
|
To add go language support in SpaceVim, you need to enable the `lang#go` layer. Press `SPC f v d` to open
|
||||||
|
SpaceVim configuration file, and add following configuration:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[layers]]
|
||||||
|
name = "lang#go"
|
||||||
|
```
|
||||||
|
|
||||||
|
for more info, you can read the [lang#go](../layers/lang/go/) layer documentation.
|
||||||
|
|
||||||
|
### code completion
|
||||||
|
|
||||||
|
By default the autocomplete layer has been enabled, so after loading `lang#go` layer, the code completion
|
||||||
|
for go language should works well.
|
||||||
|
|
||||||
|
|
||||||
|
### alternate file jumping
|
||||||
|
|
||||||
|
To manage the alternate file for a project, you may need to create a `.project_alt.json` file in the root of your
|
||||||
|
project.
|
||||||
|
|
||||||
|
for exmaple, add following content into the `.project_alt.json` file:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"src/*.go": {"alternate": "test/{}.go"},
|
||||||
|
"test/*.go": {"alternate": "src/{}.go"}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
with this configuration, you can jump between the source code and test file via command `:A`
|
||||||
|
|
||||||
|
|
||||||
|
### code running
|
||||||
|
|
||||||
|
The default code running key binding is `SPC l r`. It will run `go run current_file` asynchronously.
|
||||||
|
And the stdout will be shown on a runner buffer.
|
||||||
|
|
||||||
|
![gorun](https://user-images.githubusercontent.com/13142418/50751761-22300200-1286-11e9-8b4f-76836438d913.png)
|
||||||
|
|
||||||
|
|
||||||
|
### project building
|
||||||
|
|
||||||
|
Key binding for building current project is `SPC l b`, It will run `go build` asynchronously.
|
||||||
|
after building successfully you should see this message on the cmdline:
|
||||||
|
|
||||||
|
```txt
|
||||||
|
vim-go: [build] SUCCESS
|
||||||
|
```
|
||||||
|
|
||||||
|
### run test
|
||||||
|
|
||||||
|
There are two key bindings for running test, `SPC l t` run test for current file,
|
||||||
|
`SPC l T` only run test for current function. if the test is passed, you should see
|
||||||
|
following message on cmdline:
|
||||||
|
|
||||||
|
```txt
|
||||||
|
vim-go: [test] SUCCESS
|
||||||
|
```
|
||||||
|
|
||||||
|
### code coverage
|
||||||
|
|
||||||
|
Key binding for showing the coverage of your source code is `SPC l c`, it will call `GoCoverageToggle` command from vim-go.
|
||||||
|
|
||||||
|
![cov](https://user-images.githubusercontent.com/13142418/57342383-57375d00-7171-11e9-9182-281d7a792c68.gif)
|
||||||
|
|
||||||
|
### code format
|
||||||
|
|
||||||
|
The format layer use neoformat as default tool to format code, it will run `gofmt` on current file.
|
||||||
|
And the default key binding is `SPC b f`.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[layers]]
|
||||||
|
name = "format"
|
||||||
|
```
|
84
docs/_posts/2019-01-08-use-vim-as-a-go-ide.md
Normal file
84
docs/_posts/2019-01-08-use-vim-as-a-go-ide.md
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
---
|
||||||
|
title: "使用 Vim 搭建 Go 开发环境"
|
||||||
|
categories: [tutorials_cn, blog_cn]
|
||||||
|
images: https://user-images.githubusercontent.com/13142418/57321608-4a484880-7134-11e9-8e43-5fa05085d7e5.png
|
||||||
|
excerpt: "这篇文章主要介绍如何使用 SpaceVim 搭建 Go 的开发环境,简介 lang#go 模块所支持的功能特性以及使用技巧"
|
||||||
|
permalink: /cn/:title/
|
||||||
|
lang: cn
|
||||||
|
type: BlogPosting
|
||||||
|
comments: true
|
||||||
|
commentsID: "使用 Vim 搭建 Go 开发环境"
|
||||||
|
---
|
||||||
|
|
||||||
|
# [Blogs](../blog/) >> 使用 Vim 搭建 Go 开发环境
|
||||||
|
|
||||||
|
SpaceVim 是一个模块化的 Vim IDE,针对 Go 这一语言的支持主要依靠 `lang#go` 模块以及与之相关的其他模块。
|
||||||
|
的这篇文章主要介绍如何使用 SpaceVim 搭建 Go 的开发环境,侧重介绍跟 Go 开发相关使用技巧。
|
||||||
|
在阅读这篇文章之前,可以先阅读《[使用 Vim 搭建基础的开发环境](../use-vim-as-ide/)》,对语言相关以外的功能有一个大致的了解。
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc GFM -->
|
||||||
|
|
||||||
|
- [安装模块](#安装模块)
|
||||||
|
- [代码自动补全](#代码自动补全)
|
||||||
|
- [语法检查](#语法检查)
|
||||||
|
- [工程文件跳转](#工程文件跳转)
|
||||||
|
- [快速运行](#快速运行)
|
||||||
|
- [编译构建](#编译构建)
|
||||||
|
- [代码格式化](#代码格式化)
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
|
### 安装模块
|
||||||
|
|
||||||
|
SpaceVim 初次安装时默认并未启用相关语言模块。首先需要启用
|
||||||
|
`lang#go` 模块, 通过快捷键 `SPC f v d` 打开配置文件,添加:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[layers]]
|
||||||
|
name = "lang#go"
|
||||||
|
```
|
||||||
|
|
||||||
|
该模块主要包括插件 vim-go,在使用 neovim 和 deoplete 时,还包括了 deoplete-go。
|
||||||
|
启用 `lang#go` 模块后,在打开 Go 文件时,就可以使用语言专属快捷键,这些快捷键都是以 `SPC l` 为前缀的。
|
||||||
|
|
||||||
|
### 代码自动补全
|
||||||
|
|
||||||
|
`autocomplete` 模块为 SpaceVim 提供了自动补全功能,
|
||||||
|
该模块会根据当前环境自动在多种补全引擎之间选择合适的,
|
||||||
|
默认的补全引擎有:deoplete、neocomplete、ycm、asyncomplete 以及 neocomplcache。
|
||||||
|
几种自动补全引擎当中,要数 deoplete 的体验效果最好。
|
||||||
|
|
||||||
|
### 语法检查
|
||||||
|
|
||||||
|
`checkers` 模块为 SpaceVim 提供了语法检查的功能,该模块默认已经载入。该模块默认使用 [neomake](https://github.com/neomake/neomake)
|
||||||
|
这一异步语法检查工具。对于 luac 的支持,是通过异步调用 luac 命令来完成的。
|
||||||
|
|
||||||
|
### 工程文件跳转
|
||||||
|
|
||||||
|
SpaceVim 自带工程管理插件,可以识别项目根目录,自动跳转alternate文件。
|
||||||
|
|
||||||
|
### 快速运行
|
||||||
|
|
||||||
|
在编辑 Go 文件时,可以快速运行当前文件,这个功能有点类似于 vscode 的 code runner 插件,默认的快捷键是 `SPC l r`。按下后,
|
||||||
|
会在屏幕下方打开一个插件窗口,运行的结果会被展示在窗口内。于此同时,光标并不会跳到该插件窗口,避免影响编辑。在这里需要说明下,
|
||||||
|
这一功能是根据当前文件的路径调用相对应的 Go 命令。因此,在执行这个快捷键之前,应当先保存一下该文件。
|
||||||
|
|
||||||
|
![gorun](https://user-images.githubusercontent.com/13142418/51752665-f8cefd00-20f2-11e9-8057-d88d3509e9c3.gif)
|
||||||
|
|
||||||
|
### 编译构建
|
||||||
|
|
||||||
|
通过快捷键 `SPC l b` 异步执行 `go build`,并将结果展示在底部窗口。
|
||||||
|
|
||||||
|
```txt
|
||||||
|
vim-go: [build] SUCCESS
|
||||||
|
```
|
||||||
|
|
||||||
|
### 代码格式化
|
||||||
|
|
||||||
|
Go 代码格式化,主要依赖 `format` 模块,该模块默认使用 neoformat 这一插件,对当前文件执行 `gofmt` 命令,
|
||||||
|
默认的快捷键是 `SPC b f`。
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[layers]]
|
||||||
|
name = "format"
|
||||||
|
```
|
@ -28,6 +28,12 @@ lang: cn
|
|||||||
name = "lang#go"
|
name = "lang#go"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
默认情况下,tagbar 这一插件无法显示 go 语法树,需要安装一个依赖 [gotags](https://github.com/jstemmer/gotags):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go get -u github.com/jstemmer/gotags
|
||||||
|
```
|
||||||
|
|
||||||
## 功能特性
|
## 功能特性
|
||||||
|
|
||||||
- 代码补全
|
- 代码补全
|
||||||
|
@ -29,6 +29,12 @@ To use this configuration layer, update custom configuration file with:
|
|||||||
|
|
||||||
After the installation, run `:GoInstallBinaries` inside vim.
|
After the installation, run `:GoInstallBinaries` inside vim.
|
||||||
|
|
||||||
|
To enable tagbar support, you need to install [gotags](https://github.com/jstemmer/gotags):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go get -u github.com/jstemmer/gotags
|
||||||
|
```
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- auto-completion
|
- auto-completion
|
||||||
|
Loading…
Reference in New Issue
Block a user