Vim & Neovim
elements man editors/vimVim and Neovim use the same language server as the Elements VS Code extension. It provides diagnostics, completion, hover, go-to-definition, references, rename, and project-wide symbol search.
Elements builds no editor UI of its own. The server implements the standard Language Server Protocol (LSP), and your editor's own LSP client displays its diagnostics, completions and hover text. The plugins you already use (telescope, trouble, nvim-cmp, coc, the quickfix list) work with Elements unchanged.
Install
Nothing to do. Installing Elements installs the Vim and Neovim integration
automatically, the same way it installs the VS Code extension. No plugin manager
and no .vimrc/init.lua changes required.
- Neovim: a self-contained
plugin/elements.luais placed in your config dir (~/.config/nvim/plugin/). That directory is always on the runtimepath, so it loads whether or not you use a plugin manager (lazy.nvim, packer, ...). - Classic Vim: the plugin is installed as a native package under
~/.vim/pack/elements/start/vim-elements, which Vim auto-loads. Every file Elements installs for classic Vim is under~/.vim/pack/elements, so it never writes into a pack directory of your own.
The plugin only attaches inside an Elements project (a directory with an
.elements/id marker), so it never interferes with your other work. If you'd
rather configure the language server yourself (e.g. through
nvim-lspconfig), see the snippet under Neovim below.
Neovim
Neovim (0.8+) has a built-in LSP client, so the integration works
after install, with nothing to configure. The plugin registers the Elements server for
.jsoc, .ehtml, .ts, .js, and .css files in an Elements project, and
every plugin that uses Neovim's built-in LSP client shows the Elements
server's results:
- Symbol search:
vim.lsp.buf.workspace_symbol(), or Telescope'slsp_dynamic_workspace_symbols/ fzf-lua'slsp_live_workspace_symbols. - Diagnostics: pushed project-wide (an error your edit causes in a file you
never opened still shows up). Browse them with
vim.diagnostic.setqflist(), trouble.nvim, or fzf-lua. - Completion: via nvim-cmp or blink.cmp using the built-in LSP source.
- Hover, definition, references, rename:
vim.lsp.buf.*and your keymaps.
If you configure language servers with nvim-lspconfig, configure it to
launch the same binary instead of using the bundled plugin:
init.luavim.lsp.config('elements', { cmd = { vim.fn.expand('~/elements/bin/elements-lsp'), 'stdio' }, filetypes = { 'jsoc', 'ehtml', 'typescript', 'javascript', 'css' }, root_markers = { '.elements' }, }) vim.lsp.enable('elements')
Classic Vim
Classic Vim has no built-in LSP client, so Elements bundles one (vim-lsp (opens in a new tab)) and loads it on demand. it works with nothing to install. Elements loads the bundled vim-lsp only when you have no LSP client of your own:
- You already use vim-lsp: Elements registers with it; the bundled copy is never loaded.
- You use coc.nvim or ALE: Elements loads no client (loading a second client would run the language server twice). Configure Elements through your client instead. See below.
- You have no client: Elements loads its bundled vim-lsp automatically.
With vim-lsp, the usual commands work:
Commands:LspDefinition :LspHover :LspWorkspaceSymbol :LspDocumentDiagnostics
To turn the integration off:
.vimrclet g:elements_lsp_enabled = 0 " disable Elements LSP entirely let g:elements_lsp_no_bundle = 1 " never load the bundled vim-lsp
If you use coc.nvim, add Elements to :CocConfig:
coc-settings.json{ "languageserver": { "elements": { "command": "elements-lsp", "args": ["stdio"], "filetypes": ["jsoc", "ehtml", "typescript", "javascript", "css"], "rootPatterns": [".elements"] } } }
Syntax highlighting
Templates are HTML with a TypeScript frontmatter and { } bindings, which
Vim's stock HTML syntax doesn't understand, such as a bare > or && in the
frontmatter, or the } closing a binding, comes out flagged as an error. Both
editors get Elements' own syntax instead, which highlights the frontmatter as
TypeScript and colors e: directives and bindings.
It applies to .ehtml files, which get the ehtml filetype. Plain .html
files keep Vim's own filetype and syntax, untouched. In Neovim the html
treesitter parser is registered for ehtml, so plugins that need a treesitter syntax
tree (such as nvim-ts-autotag) still have one. The parser's highlighting is
turned off, and the Elements syntax highlights the file.
Elements also highlights .jsoc config files, in both editors.
Indentation and wrapping
Templates get an indenter that handles the TypeScript frontmatter, the markup,
an opening tag whose attributes continue onto the following lines, and a
sql( template literal whose body is SQL. A line that starts with a closing
tag or a closing bracket is indented to match the line that opened it.
Auto-wrapping is turned off in templates and .jsoc files. Vim's default
formatoptions includes t, which breaks any line past textwidth as you
type it. In prose that is what you want; in code it writes a syntax error into
the file, mid attribute or mid binding:
Wrong<form onsubmit={() => onLogin(handle, () => handle = "")}>
That is not valid: a newline is not allowed before =>. Only t is removed,
so c still wraps comments and textwidth is left alone, which means gq
still reflows a paragraph to it.
The indenter and the auto-wrap setting apply to every .ehtml file.
How the plugin connects to the language server
The plugin launches elements-lsp stdio, which ensures the build server is
running and bridges the editor's stdin/stdout to that project's LSP socket. VS Code
connects to the same server over the same protocol. VS Code connects to the
socket directly, and Vim and Neovim connect through the elements-lsp stdio
child process.
Troubleshooting
- No diagnostics or completion in Neovim: confirm you're inside an Elements project
(
.elements/idexists) and that~/elements/binis onPATH(or setELEMENTS_SYSTEM_PATH). Check:checkhealth vim.lspand:LspInfo-style client lists with:lua =vim.lsp.get_clients(). - No diagnostics or completion in classic Vim: the bundled vim-lsp loads only when you
have no client of your own. If you use coc.nvim or ALE, configure Elements
in that client (above); Elements does not load a second client. Confirm the bundle is
installed with
:echo globpath(&packpath, 'pack/*/opt/vim-lsp'), and that it loaded with:echo exists(':LspDefinition'). - A template has no Elements highlighting: check
:set filetype? syntax?. Both should readehtml. If the filetype ishtml, the file is named.html: Elements HTML files end in.ehtml. If the syntax is empty, confirm~/.config/nvim/syntax/ehtml.vim(Neovim) or~/.vim/pack/elements/start/vim-elements/(Vim) is installed. - Logs: server-side detail is in
elements logs -service build.