VimScript Language Server
The `vim-language-server` package provides Language Server Protocol (LSP) features specifically for VimScript, enhancing the development experience within Vim and Neovim environments. It offers core LSP functionalities such as auto-completion, function signature help, hover documentation, go-to-definition, find references, document symbols, and diagnostics. The current stable version is 2.3.1, with releases occurring periodically to introduce new features or improve parsing capabilities, as seen by the recent v2.3.0 update that included an `vimlparser` update. Its key differentiators include its dedicated support for VimScript, robust integration with popular Vim LSP clients like `coc.nvim` and `vim-easycomplete`, and configurable indexing options for performance tuning. This server is designed to be run as a standalone process or managed by an LSP client, rather than being imported as a programmatic library in JavaScript or TypeScript applications.
Common errors
-
Error: "command like `fixdel` in vimrc which neovim does not support will report error."
cause The `isNeovim` option is set to `true` in `initializationOptions`, but your VimScript contains commands not recognized by Neovim.fixSet `isNeovim: false` in your LSP client's configuration for the server, or modify your VimScript to remove/handle Neovim-incompatible commands. -
LSP features (completion, diagnostics) are slow or unresponsive.
cause The default indexing configuration (`initializationOptions.indexes`) is not optimized for your project size or system resources.fixIncrease `initializationOptions.indexes.count` (e.g., to 5 or more) and decrease `initializationOptions.indexes.gap` (e.g., to 50 or less) to speed up file indexing.
Warnings
- breaking Major version `v2.0.0` was released without detailed breaking changes noted in the provided changelog. Users upgrading from v1.x may encounter unexpected behavior or require configuration adjustments.
- gotcha Setting `initializationOptions.isNeovim: true` can cause errors if your VimScript files contain commands that are specific to Vim and not supported by Neovim (e.g., `fixdel`).
- gotcha Performance issues such as slow completion or diagnostics can occur, especially in large projects, due to default indexing settings.
Install
-
npm install vim-language-server -
yarn add vim-language-server -
pnpm add vim-language-server
Imports
- vim-language-server (CLI)
import { startServer } from 'vim-language-server'npm install -g vim-language-server vim-language-server --stdio
- module path for LSP clients
require('/path/to/vim-language-server/bin/index.js')"module": "/path/to/vim-language-server/bin/index.js"
- command for LSP clients
"command": "vim-language-server"
Quickstart
{
// First, install the language server globally:
// npm install -g vim-language-server
// To use with coc.nvim, add the following to your coc-settings.json:
// This configuration tells coc.nvim how to launch and interact with the server.
"languageserver": {
"vimls": {
// Option 1: Using Node.js IPC (Inter-Process Communication) for potentially faster communication.
// Ensure the path to index.js is correct for your installation.
// You can find it by running `npm root -g` and then looking inside `vim-language-server/bin/index.js`.
"module": "/usr/local/lib/node_modules/vim-language-server/bin/index.js", // Example path, adjust as needed
"args": ["--node-ipc"],
// Option 2 (alternative to "module"): Using standard I/O for communication.
// This assumes `vim-language-server` is in your system's PATH.
// "command": "vim-language-server",
// "args": ["--stdio"],
"initializationOptions": {
"isNeovim": true, // Set to true if you are using Neovim, false for Vim8+
"iskeyword": "@,48-57,_,192-255,-#", // Customize Vim's `iskeyword` option
"vimruntime": "$VIMRUNTIME", // Path to your $VIMRUNTIME directory
"runtimepath": "~/.config/nvim,~/.vim", // Comma-separated list of runtime paths
"diagnostic": { "enable": true }, // Enable diagnostics
"indexes": {
"runtimepath": true, // Index vim files from runtimepath for suggestions
"gap": 50, // Indexing time gap in ms
"count": 5 // Number of files to index concurrently
},
"suggest": {
"fromVimruntime": true,
"fromRuntimepath": true
}
},
"filetypes": [ "vim" ] // Specify file types this server should handle
}
}
}