Home

Awesome

vim-lsp Gitter

Async Language Server Protocol plugin for vim8 and neovim.

Installing

Install vim-plug and then:

Plug 'prabirshrestha/vim-lsp'

Performance

Certain bottlenecks in Vim script have been implemented in lua. If you would like to take advantage of these performance gains use vim compiled with lua or neovim v0.4.0+

Registering servers

if executable('pylsp')
    " pip install python-lsp-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pylsp',
        \ 'cmd': {server_info->['pylsp']},
        \ 'allowlist': ['python'],
        \ })
endif

function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    setlocal signcolumn=yes
    if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> gs <plug>(lsp-document-symbol-search)
    nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
    nmap <buffer> gr <plug>(lsp-references)
    nmap <buffer> gi <plug>(lsp-implementation)
    nmap <buffer> gt <plug>(lsp-type-definition)
    nmap <buffer> <leader>rn <plug>(lsp-rename)
    nmap <buffer> [g <plug>(lsp-previous-diagnostic)
    nmap <buffer> ]g <plug>(lsp-next-diagnostic)
    nmap <buffer> K <plug>(lsp-hover)
    nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
    nnoremap <buffer> <expr><c-d> lsp#scroll(-4)

    let g:lsp_format_sync_timeout = 1000
    autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
    
    " refer to doc to add more commands
endfunction

augroup lsp_install
    au!
    " call s:on_lsp_buffer_enabled only for languages that has the server registered.
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END

Refer to vim-lsp-settings on how to easily setup language servers using vim-lsp automatically.

Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'

auto-complete

Refer to docs on configuring omnifunc or asyncomplete.vim.

Snippets

vim-lsp does not support snippets by default. If you want snippet integration, you will first have to install a third-party snippet plugin and a plugin that integrates it in vim-lsp. At the moment, you have following options:

  1. vim-vsnip together with vim-vsnip-integ
  2. UltiSnips together with vim-lsp-ultisnips
  3. neosnippet.vim together with vim-lsp-neosnippet

For more information, refer to the readme and documentation of the respective plugins.

Folding

You can let the language server automatically handle folding for you. To enable this, you have to set 'foldmethod', 'foldexpr' and (optionally) 'foldtext':

set foldmethod=expr
  \ foldexpr=lsp#ui#vim#folding#foldexpr()
  \ foldtext=lsp#ui#vim#folding#foldtext()

If you would like to disable folding globally, you can add this to your configuration:

let g:lsp_fold_enabled = 0

Also see :h vim-lsp-folding.

Semantic highlighting

vim-lsp supports the unofficial extension to the LSP protocol for semantic highlighting (https://github.com/microsoft/vscode-languageserver-node/pull/367). This feature requires Neovim highlights, or Vim with the textprop feature enabled. You will also need to link language server semantic scopes to Vim highlight groups. Refer to :h vim-lsp-semantic for more info.

Supported commands

Note:

CommandDescription
:LspAddTreeCallHierarchyIncomingFind incoming call hierarchy for the symbol under cursor, but add the result to the current list
:LspCallHierarchyIncomingFind incoming call hierarchy for the symbol under cursor
:LspCallHierarchyOutgoingFind outgoing call hierarchy for the symbol under cursor
:LspCodeActionGets a list of possible commands that can be applied to a file so it can be fixed (quick fix)
:LspCodeLensGets a list of possible commands that can be executed on the current document
:LspDeclarationGo to the declaration of the word under the cursor, and open in the current window
:LspDefinitionGo to the definition of the word under the cursor, and open in the current window
:LspDocumentDiagnosticsGet current document diagnostics information
:LspDocumentFormatFormat entire document
:LspDocumentRangeFormatFormat document selection
:LspDocumentSymbolShow document symbols
:LspHoverShow hover information
:LspImplementationShow implementation of interface in the current window
:LspNextDiagnosticjump to next diagnostic (all of error, warning, information, hint)
:LspNextErrorjump to next error
:LspNextReferencejump to next reference to the symbol under cursor
:LspNextWarningjump to next warning
:LspPeekDeclarationGo to the declaration of the word under the cursor, but open in preview window
:LspPeekDefinitionGo to the definition of the word under the cursor, but open in preview window
:LspPeekImplementationGo to the implementation of an interface, but open in preview window
:LspPeekTypeDefinitionGo to the type definition of the word under the cursor, but open in preview window
:LspPreviousDiagnosticjump to previous diagnostic (all of error, warning, information, hint)
:LspPreviousErrorjump to previous error
:LspPreviousReferencejump to previous reference to the symbol under cursor
:LspPreviousWarningjump to previous warning
:LspReferencesFind references
:LspRenameRename symbol
:LspStatusShow the status of the language server
:LspTypeDefinitionGo to the type definition of the word under the cursor, and open in the current window
:LspTypeHierarchyView type hierarchy of the symbol under the cursor
:LspWorkspaceSymbolSearch/Show workspace symbol

Diagnostics

Document diagnostics (e.g. warnings, errors) are enabled by default, but if you preferred to turn them off and use other plugins instead (like Neomake or ALE, set g:lsp_diagnostics_enabled to 0:

let g:lsp_diagnostics_enabled = 0         " disable diagnostics support

Highlight references

Highlight references to the symbol under the cursor (enabled by default). You can disable it by adding

let g:lsp_document_highlight_enabled = 0

to your configuration.

To change the style of the highlighting, you can set or link the lspReference highlight group, e.g.:

highlight lspReference ctermfg=red guifg=red ctermbg=green guibg=green

Debugging

In order to enable file logging set g:lsp_log_file.

let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')

" for asyncomplete.vim log
let g:asyncomplete_log_file = expand('~/asyncomplete.log')

You can get detailed status on your servers using :CheckHealth with a plugin on vim:

if !has('nvim') | Plug 'rhysd/vim-healthcheck' | endif
CheckHealth

Tests

vim-themis is used for testing. To run integration tests gopls executable must be in path.

Maintainers

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

<a href="https://opencollective.com/vim-lsp/backer/0/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/0/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/1/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/1/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/2/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/2/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/3/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/3/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/4/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/4/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/5/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/5/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/6/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/6/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/7/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/7/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/8/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/8/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/9/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/9/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/10/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/10/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/11/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/11/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/12/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/12/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/13/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/13/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/backer/14/website" target="_blank"><img src="https://opencollective.com/vim-lsp/backer/14/avatar.svg"></a>

Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

<a href="https://opencollective.com/vim-lsp/sponsor/0/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/0/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/1/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/1/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/2/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/2/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/3/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/3/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/4/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/4/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/5/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/5/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/6/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/6/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/7/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/7/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/8/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/8/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/9/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/9/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/10/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/10/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/11/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/11/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/12/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/12/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/13/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/13/avatar.svg"></a> <a href="https://opencollective.com/vim-lsp/sponsor/14/website" target="_blank"><img src="https://opencollective.com/vim-lsp/sponsor/14/avatar.svg"></a>