Tinymist Neovim Support for Typst
Run and configure tinymisttinymist in Neovim with support for all major distros and package managers.
- Language service (completion, definitions, etc.)
- Code Formatting
- Live Web Preview with typst-preview.
tinymisttinymist features is underway. This will include: exporting to different file types, template preview, and multifile support. Neovim integration is behind VS Code currently but should be caught up in the near future.- (Recommended) mason.nvim, installing the server with the
:MasonInstall tinymist:MasonInstall tinymistcommand. In distributions like LazyVim, adding"tinymist""tinymist"to theensure_installedensure_installedtable of their mason.nvim integration installs the server as well; plain mason.nvim has noensure_installedensure_installedoption, so that form installs nothing without such an integration. -
Or manually:
To enable LSP, you must install
tinymisttinymist. You can findtinymisttinymistby:-
Night versions available at GitHub Actions.
-
Stable versions available at GitHub Releases.
If you are using the latest version of typst-ts-mode, then you can use commandtypst-ts-lsp-download-binarytypst-ts-lsp-download-binaryto download the latest stable binary oftinymisttinymistattypst-ts-lsp-download-pathtypst-ts-lsp-download-path. -
Build from source by cargo. You can also compile and install latest
tinymisttinymistby Cargo.
-
-
With
lspconfiglspconfig: -
Or with
Coc.nvimCoc.nvim: -
Or finally with the builtin lsp protocol:
For a full list of available settings see Tinymist Server Configuration.
Beside the routes above, this repository itself ships a canonical Neovim plugin in editors/neovimeditors/neovim: lua/tinymistlua/tinymist provides a require("tinymist")require("tinymist") setup that layers over the lspconfig route and additionally delivers configuration through init_optionsinit_options (the initializationOptionsinitializationOptions channel) and exposes the tinymist/devEventtinymist/devEvent notification API that the end-to-end specs in spec/spec/ use to verify editor behavior.
The plugin is the reference implementation of a tinymist editor client: its functionality is documented in Specification.md, development is described in the contributing guide, and samples/samples/ contains ready-made LazyVim and Nixvim setups.
Either typstyletypstyle or typstfmttypstfmt can be used. Both are now included in tinymisttinymist, so you do not need to install them separately if you only intend to use them through tinymisttinymist. You can select the one you prefer using the formatterModeformatterMode setting. The following snippet shows all formatting settings that you can put in the settingssettings table of the snippets from the previous section:
Note that, since this Neovim PR, neovim uses LSP servers (hence tinymisttinymist in our case) by default when formatting code. This applies to calls to vim.lsp.buf.format()vim.lsp.buf.format() (which formats the whole current buffer) and also to the gqgq command. Also note that tinymist provides the formatting capability through a dynamic registration: right after the client attaches, the registration may not have completed yet, in which case vim.lsp.buf.format()vim.lsp.buf.format() reports no matching language servers, and gqgq silently falls back to Neovim’s own reformatting, which does not preserve Typst code. The registration settles shortly after the server starts.
Live preview can be achieved with either a web preview or a pdf reader that supports automatic reloading (zathura is good).
Web Preview
See typst-preview for more installation and configuration options. Note that typst-preview.nvim downloads and runs its own tinymisttinymist binary for the preview, pinned and updated by the plugin, independent of the language server configured above — the two versions can differ.
Background Preview
Instead of a plugin, the server itself can run a background preview: the preview.background.enabledpreview.background.enabled configuration starts a preview server when the language server starts. This is an initialization-time option — the server reads it only at startup, so it must be set through init_optionsinit_options (the initializationOptionsinitializationOptions channel); setting it via settingssettings has no effect:
Pdf Preview
This preview method is slower because of compilation delays, and additional delays in the pdf reader refreshing.
It is often useful to have a command that opens the current file in the reader.
os.executeos.execute can be used instead. This is not suggested. See Issue #1606 for more information.Make sure to change exportPdfexportPdf to “onType” or “onSave”.
When working under power-saving mode or with resource-consumed projects, typst compilations costs too much CPU and memory resources. You can configure the extension to run in syntax only mode, i.e. stopping full document compilation and semantic analysis, while elementary tasks like syntax checking, syntax-level analysis (which keeps features like hover and definition working), and formatting still run, by setting the tinymist.syntaxOnlytinymist.syntaxOnly to enableenable or onPowerSavingonPowerSaving in the configuration.
For more information about power-saving mode, see Syntax-Only Mode.
Tinymist cannot know the main file of a multiple-files project if you don’t tell it explicitly. This causes the well-known label error when editing the /sub.typ/sub.typ file in a project like that:
The solution is a bit internal, which should get further improvement, but you can pin a main file by command.
Note that vim.v.nullvim.v.null should be used instead of nilnil in the argumentsarguments table when unpinning. See issue #1595.
For Neovim versions prior to 0.11.0, vim.lsp.buf.execute_commandvim.lsp.buf.execute_command should be used instead:
It also doesn’t remember the pinned main file across sessions, so you may need to run the command again after restarting Neovim.
This could be improved in the future.
Generally you can find in depth information via the :mes:mes command. :checkhealth vim.lsp:checkhealth vim.lsp can also provide valuable information, including the exact location of the language server log, which Neovim maintains in lsp.loglsp.log under stdpath('state')stdpath('state') and which collects the messages tinymist prints. Reporting bugs is welcome.
Recent versions of Neovim recognize the .typ.typ file extension as a typsttypst source file out of the box. In older versions, this is most commonly due to nvim not recognizing the extension, and it can be resolved with:
In those versions an autocommand may be necessary:
Please check the contributing guide for more information on how to contribute to the project.