\ })
```
-If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the VimEnter autocmd to initialize the LSP server and to set the LSP server options. For example:
+If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the LspSetup User autocmd to initialize the LSP server and to set the LSP server options. For example:
```viml
let lspOpts = #{autoHighlightDiags: v:true}
-autocmd VimEnter * call LspOptionsSet(lspOpts)
+autocmd User LspSetup call LspOptionsSet(lspOpts)
let lspServers = [#{
\ name: 'clang',
\ path: '/usr/local/bin/clangd',
\ args: ['--background-index']
\ }]
-autocmd VimEnter * call LspAddServer(lspServers)
+autocmd User LspSetup call LspAddServer(lspServers)
```
## Supported Commands
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 9.0 and above
-Last change: Feb 7, 2024
+Last change: Feb 13, 2024
==============================================================================
CONTENTS *lsp-contents*
function accepts a list of language servers with the above information.
If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
-LSP plugin, then you need to use the VimEnter autocmd to initialize the
+LSP plugin, then you need to use the LspSetup User autocmd to initialize the
language server and to set the language server options. For example: >
vim9script
var lspOpts = {autoHighlightDiags: true}
- autocmd VimEnter * LspOptionsSet(lspOpts)
+ autocmd User LspSetup LspOptionsSet(lspOpts)
var lspServers = [
{
args: ['--background-index']
}
]
- autocmd VimEnter * LspAddServer(lspServers)
+ autocmd User LspSetup LspAddServer(lspServers)
<
*lsp-options* *LspOptionsSet()*
*g:LspOptionsSet()*
==============================================================================
11. Autocommands *lsp-autocmds*
+ *LspSetup*
+LspSetup A |User| autocommand fired when the LSP plugin
+ is loaded. Can be used to add language
+ servers using the |LspAddServer()| function
+ and to set plugin options using the
+ |LspOptionsSet()| function.
+
*LspAttached*
LspAttached A |User| autocommand fired when the LSP client
attaches to a buffer. Can be used to configure
finish
endif
-vim9script
+vim9script noclear
# Language Server Protocol (LSP) plugin for vim
+if get(g:, 'loaded_lsp', false)
+ finish
+endif
g:loaded_lsp = true
import '../autoload/lsp/options.vim'
endif
endif
+# Invoke autocmd to register LSP servers and to set LSP options
+if exists('#User#LspSetup')
+ :doautocmd <nomodeline> User LspSetup
+endif
+
# vim: shiftwidth=2 softtabstop=2