spacevim/docs/_posts/2019-01-07-use-vim-as-a-go-ide.md
JIe 2bb7059579
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
init
2024-08-21 14:17:26 +08:00

3.5 KiB

title categories image description type comments commentsID language
Use Vim as a Go IDE
tutorials
blog
https://img.spacevim.org/57321608-4a484880-7134-11e9-8e43-5fa05085d7e5.png A general guide for using SpaceVim as Go IDE, including layer configuration, requiems installation and usage. article true Use Vim as a Go IDE Golang

Blogs >> 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:

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:

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

for more info, you can read the lang#go layer documentation.

Language server

There are two ways to setup the golang language server protocol.

neovim(>=0.5.0)

If you are using nvim(>=0.5.0). You need to use enabled_clients to specific the language servers. for example:

[[layers]]
    name = 'lsp'
    enabled_clients = ['gopls']

vim or neovim(<0.5.0)

To enable language server protocol support, you may need to enable lsp layer.

[[layers]]
  name = "lsp"
  filetypes = [
    "go"
  ]

code completion

By default the autocomplete layer has been enabled, so after loading lang#go layer, the code completion for go language should work 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 example, add following content into the .project_alt.json file:

{
  "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

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:

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:

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

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.

[[layers]]
  name = "format"