Skip to content

Commit 0f6027f

Browse files
ainar-gstamblerre
authored andcommitted
gopls/doc/vim.md: add table of contents, improve neovim docs
Change-Id: Ibc56cb676200df4282eeb38d0f63f239d2f962ab Reviewed-on: https://go-review.googlesource.com/c/tools/+/278832 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
1 parent 34cd474 commit 0f6027f

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

gopls/doc/vim.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Vim / Neovim
22

3-
## vim-go
3+
* [vim-go](#vimgo)
4+
* [LanguageClient-neovim](#lcneovim)
5+
* [Ale](#ale)
6+
* [vim-lsp](#vimlsp)
7+
* [vim-lsc](#vimlsc)
8+
* [coc.nvim](#cocnvim)
9+
* [govim](#govim)
10+
* [Neovim v0.5.0+](#neovim)
11+
* [Installation](#neovim-install)
12+
* [Custom Configuration](#neovim-config)
13+
* [Imports](#neovim-imports)
14+
* [Omnifunc](#neovim-omnifunc)
15+
* [Additional Links](#neovim-links)
16+
17+
## <a href="#vimgo" id="vimgo">vim-go</a>
418

519
Use [vim-go] ver 1.20+, with the following configuration:
620

@@ -9,7 +23,7 @@ let g:go_def_mode='gopls'
923
let g:go_info_mode='gopls'
1024
```
1125

12-
## LanguageClient-neovim
26+
## <a href="#lcneovim" id="lcneovim">LanguageClient-neovim</a>
1327

1428
Use [LanguageClient-neovim], with the following configuration:
1529

@@ -22,7 +36,7 @@ let g:LanguageClient_serverCommands = {
2236
autocmd BufWritePre *.go :call LanguageClient#textDocument_formatting_sync()
2337
```
2438

25-
## Ale
39+
## <a href="#ale" id="ale">Ale</a>
2640

2741
Use [ale]:
2842

@@ -34,7 +48,7 @@ let g:ale_linters = {
3448

3549
see [this issue][ale-issue-2179]
3650

37-
## vim-lsp
51+
## <a href="#vimlsp" id="vimlsp">vim-lsp</a>
3852

3953
Use [prabirshrestha/vim-lsp], with the following configuration:
4054

@@ -53,7 +67,7 @@ augroup LspGo
5367
augroup END
5468
```
5569

56-
## vim-lsc
70+
## <a href="#vimlsc" id="vimlsc">vim-lsc</a>
5771

5872
Use [natebosch/vim-lsc], with the following configuration:
5973

@@ -71,7 +85,7 @@ The `log_level` and `suppress_stderr` parts are needed to prevent breakage from
7185
issues [#180](https://github.com/natebosch/vim-lsc/issues/180) and
7286
[#213](https://github.com/natebosch/vim-lsc/issues/213).
7387

74-
## coc.nvim
88+
## <a href="#cocnvim" id="cocnvim">coc.nvim</a>
7589

7690
Use [coc.nvim], with the following `coc-settings.json` configuration:
7791

@@ -96,26 +110,38 @@ The `editor.action.organizeImport` code action will auto-format code and add mis
96110
autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport')
97111
```
98112

99-
## govim
113+
## <a href="#govim" id="govim">govim</a>
100114

101115
In vim classic only, use the experimental [`govim`], simply follow the [install steps][govim-install].
102116

103-
## Neovim v0.5.0+
117+
## <a href="#neovim" id="neovim">Neovim v0.5.0+</a>
104118

105119
To use the new (still experimental) native LSP client in Neovim, make sure you
106120
[install][nvim-install] the prerelease v0.5.0 version of Neovim (aka “nightly”),
107121
the `nvim-lspconfig` configuration helper plugin, and check the
108122
[`gopls` configuration section][nvim-lspconfig] there.
109123

110-
### Custom configuration
124+
### <a href="#neovim-install" id="neovim-install">Installation</a>
125+
126+
You can use Neovim's native plugin system. On a Unix system, you can do that by
127+
cloning the `nvim-lspconfig` repository into the correct directory:
128+
129+
```sh
130+
dir="${HOME}/.local/share/nvim/site/pack/nvim-lspconfig/opt/nvim-lspconfig/"
131+
mkdir -p "$dir"
132+
cd "$dir"
133+
git clone 'https://github.com/neovim/nvim-lspconfig.git' .
134+
```
135+
136+
### <a href="#neovim-config" id="neovim-config">Custom Configuration</a>
111137

112138
You can add custom configuration using Lua. Here is an example of enabling the
113139
`unusedparams` check as well as `staticcheck`:
114140

115141
```vim
116142
lua <<EOF
117-
nvim_lsp = require "lspconfig"
118-
nvim_lsp.gopls.setup {
143+
lspconfig = require "lspconfig"
144+
lspconfig.gopls.setup {
119145
cmd = {"gopls", "serve"},
120146
settings = {
121147
gopls = {
@@ -129,7 +155,7 @@ lua <<EOF
129155
EOF
130156
```
131157

132-
### Imports
158+
### <a href="#neovim-imports" id="neovim-imports">Imports</a>
133159

134160
To get your imports ordered on save, like `goimports` does, you can define
135161
a helper function in Lua:
@@ -164,7 +190,7 @@ autocmd BufWritePre *.go lua goimports(1000)
164190

165191
(Taken from the [discussion][nvim-lspconfig-imports] on Neovim issue tracker.)
166192

167-
### Omnifunc
193+
### <a href="#neovim-omnifunc" id="neovim-omnifunc">Omnifunc</a>
168194

169195
To make your <kbd>Ctrl</kbd>+<kbd>x</kbd>,<kbd>Ctrl</kbd>+<kbd>o</kbd> work, add
170196
this to your `init.vim`:
@@ -173,7 +199,7 @@ this to your `init.vim`:
173199
autocmd FileType go setlocal omnifunc=v:lua.vim.lsp.omnifunc
174200
```
175201

176-
### Additional Links
202+
### <a href="#neovim-links" id="neovim-links">Additional Links</a>
177203

178204
* [Neovim's official LSP documentation][nvim-docs].
179205

0 commit comments

Comments
 (0)