preview.nvim/README.md
Barrett Ruth 535d4cfd5e
docs: add FAQ entry for redirecting markdown output to /tmp (#56)
Problem: the `markdown` and `github` presets write `.html` output to the
working directory, which clutters the project.

Solution: add a FAQ entry to both `README.md` and `doc/preview.txt`
showing how to override the `output` field to redirect to `/tmp`.
2026-03-11 15:43:13 -04:00

104 lines
2.2 KiB
Markdown

# preview.nvim
**Universal previewer for Neovim**
An extensible framework for compiling and previewing _any_ documents (LaTeX,
Typst, Markdown, etc.)—diagnostics included.
<video src="https://github.com/user-attachments/assets/3b4fbc31-c1c4-4429-a9dc-a68d6185ab2e" width="100%" controls></video>
## Features
- Async compilation via `vim.system()`
- Built-in presets for Typst, LaTeX (latexmk, pdflatex, tectonic), Markdown,
GitHub-flavored Markdown, AsciiDoc, PlantUML, Mermaid, and Quarto
- Compiler errors via `vim.diagnostic` or quickfix
- Previewer auto-close on buffer deletion
## Requirements
- Neovim 0.11+
## Installation
With lazy.nvim:
```lua
{
'barrettruth/preview.nvim',
init = function()
vim.g.preview = { typst = true, latex = true }
end,
}
```
Or via [luarocks](https://luarocks.org/modules/barrettruth/preview.nvim):
```
luarocks install preview.nvim
```
## Documentation
```vim
:help preview.nvim
```
## FAQ
**Q: How do I define a custom provider?**
```lua
vim.g.preview = {
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?**
```lua
vim.g.preview = {
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:
```lua
vim.g.preview = {
typst = { open = { 'sioyek', '--new-instance' } },
}
```
**Q: Markdown compilation drops `.html` files in my working directory. How do I
send output to `/tmp` instead?**
Override the `output` field. The `args` function references `ctx.output`, so the
compiled file lands wherever `output` points:
```lua
vim.g.preview = {
github = {
output = function(ctx)
return '/tmp/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.html'
end,
},
}
```
**Q: How do I set up SyncTeX (forward/inverse search)?**
See `:help preview-synctex` for full recipes covering Zathura, Sioyek, and
Okular.