Problem: viewer processes launched via a string[] `open` command were always killed on buffer deletion with no way to opt out. Configuring the plugin also required an explicit `setup()` call in a `config` hook, preventing config from being declared before the plugin loads. Solution: add a `detach` boolean to `ProviderConfig` that skips SIGTERM on buffer unload. Auto-call `setup()` from `vim.g.preview` at module load time, enabling config via lazy.nvim's `init` hook. Update vimdoc and README accordingly.
1.7 KiB
1.7 KiB
preview.nvim
Universal document previewer for Neovim
An extensible framework for compiling and previewing any documents (LaTeX, Typst, Markdown, etc.)—diagnostics included.
Features
- Async compilation via
vim.system() - Built-in presets for Typst, LaTeX (latexmk, pdflatex, tectonic), Markdown, GitHub-flavored Markdown, AsciiDoc, and Quarto
- Compiler errors via
vim.diagnosticor quickfix - Previewer auto-close on buffer deletion
Requirements
- Neovim 0.11+
Installation
With lazy.nvim:
{
'barrettruth/preview.nvim',
init = function()
vim.g.preview = { typst = true, latex = true }
end,
}
Or via luarocks:
luarocks install preview.nvim
Documentation
:help preview.nvim
FAQ
Q: How do I define a custom provider?
require('preview').setup({
rst = {
cmd = { 'rst2html' },
args = function(ctx)
return { ctx.file, ctx.output }
end,
output = function(ctx)
return ctx.file:gsub('%.rst$', '.html')
end,
},
})
Q: How do I override a preset?
require('preview').setup({
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
})
Q: How do I automatically open the output file?
Set open = true on your provider (all built-in presets have this enabled) to
open the output with vim.ui.open() after the first successful compilation in
toggle/watch mode. For a specific application, pass a command table:
require('preview').setup({
typst = { open = { 'sioyek', '--new-instance' } },
})