Language server protocol servers are nifty for background syntax highlighting, code inspection, and more. Vim can speak it with the vim-lsp plugin.

Installation

Using Vim plugins, add

Plug 'prabirshrestha/vim-lsp'

to the list of installed plugins and rerun :PlugInstall.

Configuring

Python

First, install the python-lsp-server module off Pip.

Then, in ~/.vimrc (or equivalent), add:

Personal preferences

This example is what I use and is tuned to my personal preferences. Read the docs to see all options, including what I’ve shut off.

if executable('pylsp')
    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> K <plug>(lsp-hover)
 
    let g:lsp_format_sync_timeout = 1000
    let g:lsp_diagnostics_enabled = 0
    autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
    
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