Neovim integration for leaf — a terminal Markdown previewer with a GUI-like experience.
Toggle a live preview of the current file in a vertical split. Two modes:
- buffer (default): render leaf's output into a normal scratch buffer.
Refreshes on
:w. Scrolling,/, yank — everything nvim does — just works. - terminal: run
leaf --watchinside an embedded terminal. Full TUI, but no scrolling since leaf continuously redraws.
- Neovim >= 0.11
- The leaf binary on your
$PATH(or pointcmdat it) - Optional: baleia.nvim for ANSI-colored output in buffer mode (without it, colors are stripped)
-- lazy.nvim
{
"mitubaEX/leaf.nvim",
cmd = "LeafToggle",
opts = {},
}
-- packer
use {
"mitubaEX/leaf.nvim",
config = function()
require("leaf").setup()
end,
}Calling setup() is optional — the defaults work out of the box.
:LeafToggle- Closed → opens a preview of the current file in a right-hand vertical split.
- Open, same file → closes the preview (window and process).
- Open, different file → switches the preview to that file.
The preview follows normal window semantics: :q in the preview window (or
pressing q inside leaf itself) closes both the window and the process.
No default keymaps are provided. Map it yourself:
vim.keymap.set("n", "<leader>mp", "<cmd>LeafToggle<cr>", { desc = "Toggle leaf preview" })Lua API: require("leaf").toggle() / .open() / .close().
require("leaf").setup({
mode = "buffer", -- "buffer" (scratch buffer, scrollable) | "terminal"
cmd = "leaf", -- path to the leaf executable
args = { "--watch" }, -- passed to leaf; in buffer mode `--watch`/`-w` are stripped
-- and `--inline` is auto-injected (use `args = { "--inline", "plain" }`
-- to force plain output, or `{ "--theme", "dark", "--inline" }` etc.)
width = 0.4, -- 0-1: ratio of total columns, >= 2: absolute columns
focus = false, -- move the cursor into the preview when it opens
})Any file with a path is passed straight to leaf — which files render is
governed by leaf's own config (see its extras option), not by the plugin.
In buffer mode, the preview refreshes when the source file is written
(BufWritePost). In terminal mode, leaf's own --watch handles refresh.
Run :checkhealth leaf if something doesn't work.
make test # plenary.busted test suite
make lint # stylua --check
make format # styluaMIT