A simple and opinionated modal code editor for your terminal
An LSP server is usually started when a file it should handle is opened, normally known from its extension.
By using the lsp command, it’s possible to automatically start an LSP server like that.
For each LSP server you wish to register, add this to one of your config files:
lsp "lsp-server-command" "**/*.ext"
Where "**/*.ext" is a glob pattern that, when matched against a buffer just opened,
will invoke the LSP server using "lsp-server-command".
In this case, whenever we open a buffer with the extension .ext.
If you need to inspect/debug the protocol messages, they are logged to the editor log which you can open with the open-log command.
# rust-analyzer (rust)
lsp rust-analyzer "**/*.rs"
# clangd (c/cpp)
lsp "clangd --offset-encoding=utf-8" "**/*.{c,cpp,h,hpp}"
# omnisharp (c#)
lsp "omnisharp -lsp --encoding utf-8" "**/*.cs"
# zls (zig)
lsp zls "**/*.zig"
| binding | expands to | action |
|---|---|---|
K |
: lsp-hover<enter> |
display hover information (requires a running lsp server) |
gd |
: lsp-definition<enter> |
jumps to where the symbol under the cursor is defined (requires a running lsp server) |
gr |
: lsp-references -context=2<enter> |
lists all references of the symbol under the cursor with 2 lines of context (requires a running lsp server) |
gs |
: lsp-document-symbols<enter> |
lists all symbols in the buffer (requires a running lsp server) |
rr |
: lsp-rename<enter> |
rename the symbol under the cursor (requires a running lsp server) |
ra |
: lsp-code-action<enter> |
suggests possible refactors for the region under the cursor (requires a running lsp server) |
rf |
: lsp-format<enter> |
auto-format the buffer’s content (requires a running lsp server) |
lspAutomatically starts a lsp server (by running <lsp-command>) when a buffer matching a glob <glob> is opened.
The lsp command only runs if the server is not already running.
lsp <lsp-command> <glob>lsp-startManually starts a lsp server (by running <lsp-command>).
lsp-start <lsp-command>lsp-stopStops the lsp server associated with the current buffer.
lsp-stoplsp-stop-allStops all lsp servers.
usage: lsp-stop-all
lsp-hoverDisplays lsp hover information for the item under the main cursor.
lsp-hoverlsp-definitionJumps to the location of the definition of the item under the main cursor.
lsp-definitionlsp-declarationJumps to the location of the declaration of the item under the main cursor.
lsp-declarationlsp-implementationJumps to the location of the implementation of the item under the main cursor.
lsp-implementationlsp-referencesOpens up a buffer with all references of the item under the main cursor.
Optionally overrides the <context-len> (default is 2). That is: how many lines above and under each reference to show.
lsp-references [<context-len>]lsp-renameRenames the item under the main cursor.
lsp-renamelsp-code-actionLists and then performs a code action based on the main cursor context.
lsp-code-actionlsp-document-symbolsPick and jump to a symbol in the current buffer listed by the lsp server.
lsp-document-symbolslsp-workspace-symbolsOpens up a buffer with all symbols in the workspace found by the lsp server.
Optionally pre-filters results with a <query>.
lsp-workspace-symbols [<query>]lsp-formatFormat the whole buffer.
lsp-format