Skip to content

Commit 05522b2

Browse files
dduanbenlangmuir
authored andcommitted
Add instructions for Vim 8 (swiftlang#59)
Add integration instructions for Vim 8, using https://github.com/prabirshrestha/vim-lsp. Also inluded the simplest, not-really-sourcekit-lsp-specific example for triggering autocomplete.
1 parent 374c7dd commit 05522b2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Editors/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ You will need the path to the `sourcekit-lsp` executable and the Swift toolchain
7272

7373
There is an Emacs client for SourceKit-LSP in the [main Emacs LSP repository](https://github.com/emacs-lsp/lsp-sourcekit).
7474

75+
## Vim 8
76+
77+
Install [vim-lsp](https://github.com/prabirshrestha/vim-lsp). In your `.vimrc`, configure vim-lsp to use
78+
sourcekit-lsp for Swift source files like so:
79+
80+
```
81+
if executable('sourcekit-lsp')
82+
au User lsp_setup call lsp#register_server({
83+
\ 'name': 'sourcekit-lsp',
84+
\ 'cmd': {server_info->['sourcekit-lsp']},
85+
\ 'whitelist': ['swift'],
86+
\ })
87+
endif
88+
```
89+
90+
(…assuming `sourckit-lsp` is in your PATH variable, otherwise replace `'sourcekit-lsp'` with the path to
91+
the sourcekit-lsp executable).
92+
93+
That's it! As a test, open a swift file, put cursor on top of a symbol in normal mode and
94+
run `:LspDefinition`. More commands is documented [here](https://github.com/prabirshrestha/vim-lsp#supported-commands).
95+
96+
There are many Vim solutions for code completion. For instance, you may want to use LSP for omnifunc:
97+
98+
```
99+
autocmd FileType swift setlocal omnifunc=lsp#complete
100+
```
101+
102+
With this added in `.vimrc`, you can use `<c-x><c-o>` in insert mode to trigger sourcekit-lsp completion.
103+
75104
## Other Editors
76105

77106
SourceKit-LSP should work with any editor that supports the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/)

0 commit comments

Comments
 (0)