*vim-lsp.txt* Async Language Server Protocol (LSP) for Vim 8 and Neovim. *vim-lsp* ================================================================================ CONTENTS *vim-lsp-contents* Introduction |vim-lsp-introduction| Install |vim-lsp-install| Language Servers |vim-lsp-language-servers| Configure |vim-lsp-configure-source| Wiki |vim-lsp-configure-wiki| Options |vim-lsp-options| g:lsp_diagnostics_enabled |g:lsp_diagnostics_enabled| g:lsp_auto_enable |g:lsp_auto_enable| g:lsp_preview_keep_focus |g:lsp_preview_keep_focus| g:lsp_preview_float |g:lsp_preview_float| g:lsp_preview_autoclose |g:lsp_preview_autoclose| g:lsp_preview_doubletap |g:lsp_preview_doubletap| g:lsp_insert_text_enabled |g:lsp_insert_text_enabled| g:lsp_text_edit_enabled |g:lsp_text_edit_enabled| g:lsp_diagnostics_echo_cursor |g:lsp_diagnostics_echo_cursor| g:lsp_signs_enabled |g:lsp_signs_enabled| g:lsp_signs_priority |g:lsp_signs_priority| g:lsp_signs_priority_map |g:lsp_signs_priority_map| g:lsp_virtual_text_enabled |g:lsp_virtual_text_enabled| g:lsp_highlights_enabled |g:lsp_highlights_enabled| g:lsp_textprop_enabled |g:lsp_textprop_enabled| g:lsp_use_event_queue |g:lsp_use_event_queue| g:lsp_highlight_references_enabled |g:lsp_highlight_references_enabled| g:lsp_get_vim_completion_item |g:lsp_get_vim_completion_item| g:lsp_get_supported_capabilities |g:lsp_get_supported_capabilities| g:lsp_peek_alignment |g:lsp_peek_alignment| g:lsp_preview_max_width |g:lsp_preview_max_width| g:lsp_preview_max_height |g:lsp_preview_max_height| g:lsp_signature_help_enabled |g:lsp_signature_help_enabled| g:lsp_fold_enabled |g:lsp_fold_enabled| g:lsp_hover_conceal |g:lsp_hover_conceal| g:lsp_ignorecase |g:lsp_ignorecase| g:lsp_log_file |g:lsp_log_file| Functions |vim-lsp-functions| enable |vim-lsp-enable| disable |vim-lsp-disable| register_server |vim-lsp-register_server| stop_server |vim-lsp-stop_server| utils#find_nearest_parent_file_directory |vim-lsp-utils-find_nearest_parent_file_directory| vim-lsp-get_buffer_diagnostics_counts |vim-lsp-get_buffer_diagnostics_counts| vim-lsp-get_buffer_first_error_line |vim-lsp-get_buffer_first_error_line| Commands |vim-lsp-commands| LspCodeAction |LspCodeAction| LspDocumentDiagnostics |LspDocumentDiagnostics| LspDeclaration |LspDeclaration| LspDefinition |LspDefinition| LspDocumentFold |LspDocumentFold| LspDocumentFoldSync |LspDocumentFoldSync| LspDocumentFormat |LspDocumentFormat| LspDocumentFormatSync |LspDocumentFormatSync| LspDocumentRangeFormat |LspDocumentRangeFormat| LspDocumentSymbol |LspDocumentSymbol| LspHover |LspHover| LspNextError |LspNextError| LspNextReference |LspNextReference| LspPeekDeclaration |LspPeekDeclaration| LspPeekDefinition |LspPeekDefinition| LspPeekImplementation |LspPeekImplementation| LspPeekTypeDefinition |LspPeekTypeDefinition| LspPreviousError |LspPreviousError| LspPreviousReference |LspPreviousReference| LspImplementation |LspImplementation| LspReferences |LspReferences| LspRename |LspRename| LspTypeDefinition |LspTypeDefinition| LspWorkspaceSymbol |LspWorkspaceSymbol| Autocommands |vim-lsp-autocommands| lsp_complete_done |lsp_complete_done| Mappings |vim-lsp-mappings| (lsp-preview-close) |(lsp-preview-close)| (lsp-preview-focus) |(lsp-preview-focus)| Autocomplete |vim-lsp-autocomplete| omnifunc |vim-lsp-omnifunc| asyncomplete.vim |vim-lsp-asyncomplete| Snippets |vim-lsp-snippets| Folding |vim-lsp-folding| License |vim-lsp-license| ================================================================================ INTRODUCTION *vim-lsp-introduction* Async Language Server Protocol (LSP) for Vim 8 and Neovim. For more information on LSP refer to the official website at https://microsoft.github.io/language-server-protocol/ ================================================================================ INSTALL *vim-lsp-install* Install the async.vim and vim-lsp plugins. Below is a sample using plug.vim Plug 'prabirshrestha/async.vim' Plug 'prabirshrestha/vim-lsp' Note: async.vim (https://github.com/prabirshrestha/async.vim) is required to use vim-lsp. It is used to normalize the jobs api between Vim 8 and Neovim. =============================================================================== LANGUAGE SERVERS *vim-lsp-language-servers* CONFIGURE *vim-lsp-configure* vim-lsp doesn't ship with any language servers. The user is responsible for configuring the language servers correctly. Here is an example of configuring the python language server protocol based on pyls (https://github.com/palantir/python-language-server) 1. Make sure the language server is available locally in the machine. For python, pip package manager can be used to install the language server. pip install python-language-server 2. Register the language server in your .vimrc if (executable('pyls')) au User lsp_setup call lsp#register_server({ \ 'name': 'pyls', \ 'cmd': {server_info->['pyls']}, \ 'whitelist': ['python'] \ }) endif For more details refer to |vim-lsp-register_server|. WIKI *vim-lsp-configure-wiki* For documentation on how to configure other language servers refer to https://github.com/prabirshrestha/vim-lsp/wiki/Servers =============================================================================== Options *vim-lsp-options* g:lsp_diagnostics_enabled *g:lsp_diagnostics_enabled* Type: |Number| Default: `1` Enable support for document diagnostics like warnings and error messages. enabling vim-lsp during startup. Refer to |g:lsp_signs_enabled| to enable signs column. Example: let g:lsp_diagnostics_enabled = 1 let g:lsp_diagnostics_enabled = 0 g:lsp_auto_enable *g:lsp_auto_enable* Type: |Number| Default: `1` Auto enable vim-lsp plugin during startup. Set to `0` to disable auto enabling vim-lsp during startup. Example: let g:lsp_auto_enable = 1 let g:lsp_auto_enable = 0 g:lsp_preview_keep_focus *g:lsp_preview_keep_focus* Type: |Number| Default: `1` Indicates whether to keep the focus on current window or move the focus to the |preview-window| when a |preview-window| is opened by vim-lsp. Certain commands such as |LspHover| opens the result in a |preview-window|. Example: " Keep the focus in current window let g:lsp_preview_keep_focus = 1 " Do not keep the focus in current window. " Move the focus to |preview-window|. let g:lsp_preview_keep_focus = 0 * |preview-window| can be closed using the default vim mapping - ``. g:lsp_preview_float *g:lsp_preview_float* Type: |Number| Default: `1` If set and nvim_win_open() or popup_create is available, hover information are shown in a floating window as |preview-window| at the cursor position. The |preview-window| is closed automatically on cursor moves, unless it is focused. While focused it may be closed with . This feature requires neovim 0.4.0 (current master) or Vim8.1 with has('patch-8.1.1517'). Example: > " Opens preview windows as floating let g:lsp_preview_float = 1 " Opens preview windows as normal windows let g:lsp_preview_float = 0 < After opening an autocmd User event lsp_float_opened is issued, as well as and lsp_float_closed upon closing. This can be used to alter the preview window (using lsp#ui#vim#output#getpreviewwinid() to get the window id), setup custom bindings while a preview is open, or change the highlighting of the window. Example of custom keybindings: > " Close preview window with autocmd User lsp_float_opened nmap \ (lsp-preview-close) autocmd User lsp_float_closed nunmap < Example of customising the highlighting: > highlight PopupWindow ctermbg=lightblue guibg=lightblue augroup lsp_float_colours autocmd! if !has('nvim') autocmd User lsp_float_opened \ call win_execute(lsp#ui#vim#output#getpreviewwinid(), \ 'setlocal wincolor=PopupWindow') else autocmd User lsp_float_opened \ call nvim_win_set_option(lsp#ui#vim#output#getpreviewwinid(), \ 'winhighlight', 'Normal:PopupWindow') endif augroup end < g:lsp_preview_autoclose *g:lsp_preview_autoclose* Type: |Number| Default: `1` Indicates if an opened floating preview shall be automatically closed upon movement of the cursor. If set to 1, the window will close automatically if the cursor is moved and the preview is not focused. If set to 0, it will remain open until explicitly closed (e.g. with (lsp-preview-close), or when focused). Example: " Preview closes on cursor move let g:lsp_preview_autoclose = 1 " Preview remains open and waits for an explicit call let g:lsp_preview_autoclose = 0 g:lsp_preview_doubletap *g:lsp_preview_doubletap* Type: |List| Default: `[function('lsp#ui#vim#output#focuspreview')]` When preview is called twice with the same data while the preview is still open, the function in `lsp_preview_doubletap` is called instead. To disable this and just "refresh" the preview, set to ´0´. Example: " Focus preview on repeated preview (does not work for vim8.1 popups) let g:lsp_preview_doubletap = [function('lsp#ui#vim#output#focuspreview')] " Closes the preview window on the second call to preview let g:lsp_preview_doubletap = [function('lsp#ui#vim#output#closepreview')] " Disables double tap feature; refreshes the preview on consecutive taps let g:lsp_preview_doubletap = 0 g:lsp_insert_text_enabled *g:lsp_insert_text_enabled* Type: |Number| Default: `1` Enable support for completion insertText property. Set to `0` to disable using insertText. Example: let g:lsp_insert_text_enabled = 1 let g:lsp_insert_text_enabled = 0 g:lsp_text_edit_enabled *g:lsp_text_edit_enabled* Type: |Number| Default: `1` Enable support for completion textEdit property. Set to `0` to disable using textEdit. Example: let g:lsp_text_edit_enabled = 1 let g:lsp_text_edit_enabled = 0 g:lsp_diagnostics_echo_cursor *g:lsp_diagnostics_echo_cursor* Type: |Number| Default: `0` Enables echo of diagnostic error for the current line to status. Requires |lsp_diagnostics_enabled| set to 1. Example: let g:lsp_diagnostics_echo_cursor = 1 let g:lsp_diagnostics_echo_cursor = 0 g:lsp_signs_enabled *g:lsp_signs_enabled* Type: |Number| Default: `1` for vim/neovim with patch 8.1.0772 Enables signs for diagnostics. Requires patch 8.1.0772 and |lsp_diagnostics_enabled| set to 1. Example: let g:lsp_signs_enabled = 1 let g:lsp_signs_enabled = 0 g:lsp_signs_priority *g:lsp_signs_priority* Type: |Number| Default: `10` for vim/neovim with patch 8.1.0772 Configures the |sign-priority| for placed signs. Signs placed by other plugins have a priority of 10 by default. Requires |lsp_signs_enabled| set to 1. Example: let g:lsp_signs_priority = 11 let g:lsp_signs_priority = 9 g:lsp_signs_priority_map *g:lsp_signs_priority_map* Type: |Map| Default: `{}` for vim/neovim with patch 8.1.0772 Overrides |g:lsp_signs_priority| per severity level or per server name and severity level. Requires |lsp_signs_enabled| set to 1. Example: let g:lsp_signs_priority_map = { \'LspError': 11, \'LspWarning': 7, \'clangd_LspWarning': 11, \'clangd_LspInformation': 11 \} g:lsp_virtual_text_enabled *g:lsp_virtual_text_enabled* Type: |Number| Default: `1` for neovim 0.3+ Enables virtual text to be shown next to diagnostic errors. Requires NeoVim with version 0.3 or newer. Example: > let g:lsp_virtual_text_enabled = 1 let g:lsp_virtual_text_enabled = 0 < g:lsp_virtual_text_prefix *g:lsp_virtual_text_prefix* Type: |String| Default: `""` for neovim 0.3+ Adds the prefix to the diagnostics to be shown as virtual text. Requires NeoVim with version 0.3 or newer. Example: > let g:lsp_virtual_text_prefix = "> " let g:lsp_virtual_text_prefix = " ‣ " < g:lsp_highlights_enabled *g:lsp_highlights_enabled* Type: |Number| Default: `1` for neovim 0.3+ Enables highlighting of diagnostics. Requires NeoVim with version 0.3 or newer. Example: > let g:lsp_highlights_enabled = 1 let g:lsp_highlights_enabled = 0 < To change the style of the highlighting, you can set or link `LspErrorHighlight`, `LspWarningHighlight`, `LspInformationHighlight` and `LspHintHighlight` highlight groups. Example: > highlight link LspErrorHighlight Error < g:lsp_textprop_enabled *g:lsp_textprop_enabled* Type: |Number| Default: `1` for vim with +textprop Enables highlighting of diagnostics. Requires vim with +textprop (patch 8.1.0579). Example: > let g:lsp_textprop_enabled = 1 let g:lsp_textprop_enabled = 0 < To change the style of the highlighting, you can set or link `LspErrorHighlight`, `LspWarningHighlight`, `LspInformationHighlight` and `LspHintHighlight` highlight groups. Example: > highlight LspErrorHighlight term=underline cterm=underline gui=underline < g:lsp_use_event_queue *g:lsp_use_event_queue* Type: |Number| Default: `1` for neovim or vim with patch-8.1.0889 Enable event queue which improves performance by reducing the communication between client and server. Example: let g:lsp_use_event_queue = 1 let g:lsp_use_event_queue = 0 g:lsp_highlight_references_enabled *g:lsp_highlight_references_enabled* Type: |Number| Default: `0` Enable highlighting of the references to the symbol under the cursor. Example: > let g:lsp_highlight_references_enabled = 1 let g:lsp_highlight_references_enabled = 0 < To change the style of the highlighting, you can set or link the `lspReference` highlight group. Example: > highlight lspReference ctermfg=red guifg=red ctermbg=green guibg=green < g:lsp_get_vim_completion_item *g:lsp_get_vim_completion_item* Type: |List| Default: `[function('lsp#omni#default_get_vim_completion_item')]` A |List| containing one element of type |Funcref|. This element is a reference to the function that vim-lsp should use to produce the items in the completion menu. Changing this variable allows customizing how items are displayed in the completion menu, or adding custom `user_data` to items (see |complete-items|). Note: You can reuse functionality provided by vim-lsp by calling `lsp#omni#default_get_vim_completion_item` from within your function. g:lsp_get_supported_capabilities *g:lsp_get_supported_capabilities* Type: |List| Default: `[function('lsp#default_get_supported_capabilities')]` A |List| containing one element of type |Funcref|. This element is a reference to the function that vim-lsp should use to obtain the supported LSP capabilities. Changing this variable allows customizing which capabilities vim-lsp sends to a language server. Note: You can obtain the default supported capabilities of vim-lsp by calling `lsp#omni#default_get_supported_capabilities` from within your function. g:lsp_peek_alignment *g:lsp_peek_alignment* Type: |String| Default: `"center"` Determines how to align the location of interest for e.g. |LspPeekDefinition|. Three values are possible: `"top"`, `"center"` and `"bottom"`, which place the location of interest at the first, middle and last lines of the preview/popup/floating window, respectively. g:lsp_preview_max_width *g:lsp_preview_max_width* Type: |Number| Default: `-1` If positive, determines the maximum width of the preview window in characters. Lines longer than `g:lsp_preview_max_width` will be wrapped to fit in the preview window. Use a value of `-1` to disable setting a maximum width. g:lsp_preview_max_height *g:lsp_preview_max_height* Type: |Number| Default: `-1` If positive, determines the maximum height of the preview window in characters. Use a value of `-1` to disable setting a maximum height. g:lsp_signature_help_enabled *g:lsp_signature_help_enabled* Type: |Number| Default: `1` Enable support for signature help. Set to `0` to disable. Example: > let g:lsp_signature_help_enabled = 1 let g:lsp_signature_help_enabled = 0 g:lsp_fold_enabled *g:lsp_fold_enabled* Type: |Number| Default: `1` Determines whether or not folding is enabled globally. Set to `0` to disable sending requests. g:lsp_hover_conceal *g:lsp_hover_conceal* Type: |Boolean| Default: `1` If `true` (`1`), |conceallevel| is set to `2` for hover windows. This means that, for example, asterisks in markdown hovers are hidden, but the text is still displayed bold. You may want to disable this if the filetype of the popup has custom conceals which you don't want to use, or if you're using Vim in a terminal. To override this setting per server, see |vim-lsp-hover_conceal|. g:lsp_ignorecase *g:lsp_ignorecase* Type: |Boolean| Default: the value of |'ignorecase'| Determines whether or not case should be ignored when filtering completion items. See |vim-lsp-completion-filter|. By default, the value of |'ignorecase'| is used. g:lsp_log_file *g:lsp_log_file* Type: |String| Default: `''` Determines whether or not logging should be written to a file. To disable log use empty string. Example: > let g:lsp_log_file = '' let g:lsp_log_file = expand('~/vim-lsp.log') =============================================================================== FUNCTIONS *vim-lsp-functions* lsp#enable *vim-lsp-enable* Enables vim-lsp plugin. Example: :call lsp#enable() lsp#disable *vim-lsp-disable* Disables vim-lsp plugin. Example: :call lsp#disable() lsp#register_server *vim-lsp-register_server* Used to register the language server with vim-lsp. This method takes one parameter which is a vim |dict| and is refered to as |vim-lsp-server-info| Example: if (executable('pyls')) au User lsp_setup call lsp#register_server({ \ 'name': 'name-of-server', \ 'cmd': {server_info->['server-exectuable']}, \ 'whitelist': ['filetype to whitelist'], \ 'blacklist': ['filetype to blacklist'], \ 'config': {}, \ 'workspace_config': {'param': {'enabled': v:true}}, \ }) endif Note: * checking for executable is optional but can be used to avoid unnecessary server registration. * au User lsp_setup is optional and used to delay registering the language server after .vimrc has been loaded. It is recommended to use it if possible. server_info *vim-lsp-server_info* The vim |dict| containing information about the server. { 'name': 'name of the server', 'cmd': {server_info->['server_executable']}, 'whitelist': ['filetype'], 'blacklist': ['filetype'], 'config': {}, 'workspace_config': {}, } * name: required Name of the language server. Needs to be unique. * cmd: required Function or array which represents command line to start the language server. When function, it takes |vim-lsp-server_info| as parameter and returns the language server executable to run along with the appropriate arguments when the appropriate filetype is loaded. This function will only be called when the server has not started. Return empty array to ignore starting the server. When array, the first element is the language server executable and the rest are the appropriate arguments. It is useful when the command line can be determined statically and |vim-lsp-server_info| is not necessary. Example: 'cmd': ['pyls'] Function can be complex based on custom requirements. For example: - Use binary from local node_modules folder instead of a global node_modules folder. - Use different executable based on custom config. - Return empty array to ignore starting server due to missing config value required by the server (ex: missing package.json) - Instead of checking for server executable before calling register_server it can also be checked here. Cross-platform compatibility notes: It is recommended to use &shell with &shellcmdflag when running script files that can be executed specially on windows where *.bat and *.cmd files cannot be started without running the shell first. This is common for exectuables installed by npm for nodejs. Example: 'cmd': {server_info-> \ [&shell, &shellcmdflag, 'typescript-language-server --stdio']} * whitelist: optional String array of filetypes to run the language server. Example: 'whitelist': ['javascript', 'typescript'] '*' is treated as any filetype. * blacklist: optional String array of filetypes to run the language server. Example: 'blacklist': ['javascript', 'typescript'] '*' is treated as any filetype. whitelist and blacklist can be used together. The following example says to run the language server for all filetypes except javascript and typescript. blacklist always takes higher priority over whitelist. 'whitelist': ['*'] 'blacklist': ['javascript', 'typescript'] * workspace_config: optional vim |dict| Used to pass workspace configuration to the server after initialization. Configuration settings are language-server specific. Example: 'workspace_config': {'pyls': {'plugins': \ {'pydocstyle': {'enabled': v:true}}}} * config: optional vim |dict| Used to pass additional custom config. For example: 'config': { 'prefer_local': 1 } This can then be used by cmd function. function! s:myserver_cmd(server_info) abort let l:config = get(a:server_info, 'config', {}) let l:prefer_local = get(l:config, 'prefer_local', 1) if (l:prefer_local) return ['./local-executable'] else return ['/bin/global-exectuable'] endif endfunction 'cmd': function('s:myserver_cmd') Using the `config` key, you can also specify a custom 'typed word pattern', or a custom filter for completion items, see |vim-lsp-typed_pattern| and |vim-lsp-completion-filter|. The following per-server configuration options are supported by vim-lsp. * hover_conceal Type: |Boolean| Default: |g:lsp_hover_conceal| This takes precendence over the value of |g:lsp_hover_conceal|, to allow overriding this setting per server. Example: 'config': { 'hover_conceal': 1 } * symbol_kinds Type: |Dict| Default: |{}| This allows overriding the default text mappings for symbol kinds (e.g., 'module', 'method') per server. Useful for abbreviating or removing the kind text. Example: 'config': { 'symbol_kinds': {'26': 'type' } } * completion_item_kinds Type: |Dict| Default: |{}| This allows overriding the default text mappings for completion item kinds (e.g., 'module', 'method') per server. Useful for abbreviating or removing the kind text. Example: 'config': { 'completion_item_kinds': {'26': 'type' } } typed_pattern *vim-lsp-typed_pattern* Type: |String| (|pattern|) Default: `'\k*$'` Vim-lsp will automatically detect the text you have typed so far when invoking completion. It does this by checking the textEdit's range of each completion item. If the language server doesn't use textEdits, you can use a |regexp| to determine what you have typed so far. The pattern is matched against the current line, from column 0 up until the cursor's position. Thus, |/$| means "current cursor position" in this context. For example: 'config': { 'typed_pattern': '\k*$' } This uses all characters in `'iskeyword'` in front of the cursor as typed word. This key is also used to align the completion menu: the completion menu is placed so its left border is at the column that matches the start of the `typed_pattern`. filter *vim-lsp-completion-filter* You can filter the completion items returned from the server by specifying a completion filter using the `filter` key in the server info's `config` |dict|. The value of the `filter` key is itself a |dict| containing at least a key `name`, which specifies which filter to use. For the meaning of "already typed text" in the remainder of this section, see |vim-lsp-typed_pattern|. The case (in)sensitivity of the matching is determined by |g:lsp_ignorecase|. Example: 'config': { 'filter': { 'name': 'none' } } Available filters are: - `none` (default) Do not filter completion items, use all items returned from the language server. - `prefix` Only allow completion items that are a prefix of the already typed word. - `contains` Only allow completion items that contain the already typed word. Note: After triggering completion with |i_CTRL-X_CTRL-O|, further filtering is only possible by adding to the already typed prefix (even if you're using the `contains` filter). If you'd like to retrigger the filtering, you will have to press CTRL-X CTRL-O again. lsp#stop_server *vim-lsp-stop_server* Used to stop the server. Example: call lsp#stop_server('name-of-server') Note: * If the server is not running or is not registered it is a noop. * The server is forcefully stopped without sending shutdown request. lsp#get_server_status *vim-lsp-get_server_status* Get the status of a server. Example: call lsp#get_server_status('name-of-server') Returns one of "unknown server", " "exited", "starting", "failed", "running", "not running". *vim-lsp-utils-find_nearest_parent_file_directory* utils#find_nearest_parent_file_directory Find the nearest parent directory which contains the specific files or diretories. The method has two parameters. The first is the path where searching starts. The second is the files or directories names which you want to find. The return value is the directory path which is found the most times. This method is mainly used to generate 'root_uri' when registering server. Example: if executable('ccls') au User lsp_setup call lsp#register_server({ \ 'name': 'ccls', \ 'cmd': {server_info->['ccls']}, \ 'root_uri':{server_info->lsp#utils#path_to_uri( \ lsp#utils#find_nearest_parent_file_directory( \ lsp#utils#get_buffer_path(), \ ['.ccls', 'compile_commands.json', '.git/'] \ ))}, \ 'initialization_options': {}, \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp', 'cc'], \ }) endif Note: * The second parameter can be a |String| or a string |List|. * For the second parameter, the string ends with '/' or '\' will be regarded as a directory name, otherwise as a file name. * If there is not directory with the specific files or diretories found, the method will return an empty string. lsp#get_buffer_diagnostics_counts *vim-lsp-get_buffer_diagnostics_counts* Get dict with diagnostic counts for current buffer. Useful e.g. for display in status line. Returns dictionary with keys "error", "warning", "information", "hint". lsp#get_buffer_first_error_line *vim-lsp-get_buffer_first_error_line* Get line number of first error in current buffer. Returns |Number| or |v:null| if there are no errors. =============================================================================== Commands *vim-lsp-commands* LspCodeAction *LspCodeAction* Gets a list of possible commands that can be applied to a file so it can be fixed (quick fix). LspDocumentDiagnostics *LspDocumentDiagnostics* Gets the current document diagnostics. LspDeclaration *LspDeclaration* Go to declaration. Useful for languages such as C/C++ where there is a clear distinction between declaration and definition. Also see |LspPeekDeclaration|. LspDefinition *LspDefinition* Go to definition. Also see |LspPeekDefinition|. LspDocumentFold *LspDocumentFold* Recalculate folds for the current buffer. LspDocumentFoldSync *LspDocumentFoldSync* Same as |LspDocumentFold|, but synchronous. LspDocumentFormat *LspDocumentFormat* Format the entire document. LspDocumentFormatSync *LspDocumentFormatSync* Same as |LspDocumentFormat| but synchronous. Useful when running |autocmd| commands such as formatting before save. Example: autocmd BufWritePre LspDocumentFormatSync Note that this may slow down vim. LspDocumentRangeFormat *LspDocumentRangeFormat* Format the current document selection. LspDocumentSymbol *LspDocumentSymbol* Gets the symbols for the current document. LspHover *LspHover* Gets the hover information and displays it in the |preview-window|. * |preview-window| can be closed using the default vim mapping - ``. * To control the default focus of |preview-window| for |LspHover| configure |g:lsp_preview_keep_focus|. * If using neovim with nvim_win_open() available, |g:lsp_preview_float| can be set to enable a floating preview at the cursor which is closed automatically on cursormove if not focused and can be closed with if focused. LspNextError *LspNextError* Jump to Next err diagnostics LspNextReference *LspNextReference* Jump to the next reference of the symbol under cursor. LspPeekDeclaration *LspPeekDeclaration* Like |LspDeclaration|, but opens the declaration in the |preview-window| instead of the current window. Also see |g:lsp_peek_alignment| and |g:lsp_preview_float|. LspPeekDefinition *LspPeekDefinition* Like |LspDefinition|, but opens the definition in the |preview-window| instead of the current window. Also see |g:lsp_peek_alignment| and |g:lsp_preview_float|. LspPeekImplementation *LspPeekImplementation* Like |LspImplementation|, but opens the implementation in the |preview-window| instead of the current window. Also see |g:lsp_peek_alignment| and |g:lsp_preview_float|. LspPeekTypeDefinition *LspPeekTypeDefinition* Like |LspTypeDefinition|, but opens the type definition in the |preview-window| instead of the current window. Also see |g:lsp_peek_alignment| and |g:lsp_preview_float|. LspPreviousError *LspPreviousError* Jump to Previous err diagnostics LspPreviousReference *LspPreviousReference* Jump to the previous reference of the symbol under cursor. LspImplementation *LspImplementation* Find all implementation of interface. Also see |LspPeekImplementation|. LspReferences *LspReferences* Find all references. LspRename *LspRename* Rename the symbol. LspTypeDefinition *LspTypeDefinition* Go to the type definition. Also see |LspPeekTypeDefinition|. LspWorkspaceSymbol *LspWorkspaceSymbol* Search and show workspace symbols. LspStatus *LspStatus* Prints the status of all registered servers. =============================================================================== Autocommands *vim-lsp-autocommands* lsp_complete_done *lsp_complete_done* This autocommand is run after Insert mode completion is done, similar to |CompleteDone|. However, the difference is that |lsp_complete_done| is run only after vim-lsp has finished executing its internal |CompleteDone| autocommands (e.g. applying text edits). It is thus ideal to use for snippet expansion, or custom post processing of completed items. Just like |CompleteDone|, the Vim variable |v:completed_item| contains information about the completed item. It is guaranteed that vim-lsp does not change the content of this variable during its |CompleteDone| autocommands. =============================================================================== Mappings *vim-lsp-mappings* To map keys to the feature of vim-lsp, use mappings: > autocmd FileType python,go nmap gd (lsp-definition) < Available plug mappings are following: nnoremap (lsp-code-action) nnoremap (lsp-declaration) nnoremap (lsp-peek-declaration) nnoremap (lsp-definition) nnoremap (lsp-peek-definition) nnoremap (lsp-document-symbol) nnoremap (lsp-document-diagnostics) nnoremap (lsp-hover) nnoremap (lsp-next-error) nnoremap (lsp-next-reference) nnoremap (lsp-preview-close) nnoremap (lsp-preview-focus) nnoremap (lsp-previous-error) nnoremap (lsp-previous-reference) nnoremap (lsp-references) nnoremap (lsp-rename) nnoremap (lsp-workspace-symbol) nnoremap (lsp-document-format) vnoremap (lsp-document-format) nnoremap (lsp-document-range-format) xnoremap (lsp-document-range-format) nnoremap (lsp-implementation) nnoremap (lsp-peek-implementation) nnoremap (lsp-type-definition) nnoremap (lsp-peek-type-definition) nnoremap (lsp-status) nnoremap (lsp-signature-help) See also |vim-lsp-commands| (lsp-preview-close) *(lsp-preview-close)* Closes an opened preview window (lsp-preview-focus) *(lsp-preview-focus)* Transfers focus to an opened preview window or back to the previous window if focus is already on the preview window. =============================================================================== Autocomplete *vim-lsp-autocomplete* omnifunc *vim-lsp-omnifunc* vim-lsp by default only provides basic omnifunc support for autocomplete. Completion can be made asynchronous by setting g:lsp_async_completion. Note that this may cause unexpected behavior in some plugins such as MUcomplete. If you would like to have more advanced features please use asyncomplete.vim as described below. Example: autocmd FileType typescript setlocal omnifunc=lsp#complete asyncomplete.vim *vim-lsp-asyncomplete* asyncomplete.vim is a async auto complete plugin for vim8 and neovim written in pure vim script. https://github.com/prabirshrestha/asyncomplete.vim Example: Plug 'prabirshrestha/async.vim' Plug 'prabirshrestha/vim-lsp' Plug 'prabirshrestha/asyncomplete.vim' Plug 'prabirshrestha/asyncomplete-lsp.vim' For additional configuration refer to asyncomplete.vim docs. =============================================================================== Snippets *vim-lsp-snippets* To integrate snippets in vim-lsp, 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 two options: 1. UltiSnips and vim-lsp-ultisnips https://github.com/SirVer/ultisnips https://github.com/thomasfaingnaert/vim-lsp-ultisnips 2. neosnippet.vim and vim-lsp-neosnippet https://github.com/Shougo/neosnippet.vim https://github.com/thomasfaingnaert/vim-lsp-neosnippet Refer to the readme and docs of vim-lsp-ultisnips and vim-lsp-neosnippet for more information and configuration options. =============================================================================== Folding *vim-lsp-folding* You can also let the language server handle folding for you. To enable this feature, you will have to set |'foldmethod'|, |'foldexpr'| and |'foldtext'| (the latter is optional) correctly: set foldmethod=expr \ foldexpr=lsp#ui#vim#folding#foldexpr() \ foldtext=lsp#ui#vim#folding#foldtext() Also, make sure you have not disabled folding globally, see |g:lsp_fold_enabled|. You may want to enable this only for certain filetypes, e.g. for Javascript only: augroup lsp_folding autocmd! autocmd FileType javascript setlocal \ foldmethod=expr \ foldexpr=lsp#ui#vim#folding#foldexpr() \ foldtext=lsp#ui#vim#folding#foldtext() augroup end To display open and closed folds at the side of the window, see |'foldcolumn'|. If you want to remove the dashes at the end of the folds, you can change the fold item of |'fillchars'|. =============================================================================== License *vim-lsp-license* The MIT License (MIT) Full license text: https://github.com/prabirshrestha/vim-lsp/blob/master/LICENSE vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: