Preview Markdown in your browser with synchronised scrolling, math, diagrams and flexible configuration.
- Live updates and synchronised scrolling as you type.
- Cross platform (macOS, Linux, Windows, FreeBSD), no Node.js required.
- Math with KaTeX, including chemistry via mhchem.
- Diagrams: Mermaid (with a full-screen viewer and the ELK layout), PlantUML, Graphviz, flowchart.js, js-sequence-diagrams and Chart.js.
- GitHub-flavoured extras: alerts, tables of contents, task lists, footnotes, emoji, front matter, local images with sizes.
- Themes: any shadcn/ui or tweakcn theme with your own fonts, or your own CSS.
- Share the preview with a phone or another machine, safely.
Requires Neovim or Vim 8.1+. The plugin downloads a pre-built server binary for
macOS (x64, arm64), Linux (x64, arm64), FreeBSD (x64) and Windows (x64). If the
binary is missing or out of date, :MarkdownPreview downloads it first, so the
build hooks below only make the first preview faster.
{
"sammaji/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" },
opts = {},
}No build is needed: lazy.nvim runs the plugin's build.lua on install and
update.
use({
"sammaji/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" },
run = function() vim.fn["mkdp#util#install_sync"]() end,
})Plug 'sammaji/markdown-preview.nvim', { 'do': { -> mkdp#util#install_sync() }, 'for': ['markdown', 'vim-plug'] }- mini.deps
- vim.pack (Neovim 0.12+)
- dein.vim
- Native packages, without a plugin manager
- Moving from iamcco/markdown-preview.nvim
On a platform without a pre-built binary, or to run your own build:
cargo build --releasein the plugin directory. This needs Rust 1.86+ and Node.js 20.9+ with pnpm or
npx. A target/release build is always used before a downloaded binary. Run
:checkhealth mkdp to see which binary is used.
See Installation for the details of each.
| Command | Description |
|---|---|
:MarkdownPreview |
Open the preview of the current buffer |
:MarkdownPreviewStop |
Stop the preview |
:MarkdownPreviewToggle |
Open or stop the preview |
Each command has a <Plug> mapping of the same name, e.g.
<Plug>MarkdownPreviewToggle. To map a key with lazy.nvim:
{
"sammaji/markdown-preview.nvim",
-- ...
keys = {
{ "<leader>mp", "<cmd>MarkdownPreviewToggle<cr>", ft = "markdown", desc = "Markdown preview" },
},
}To see every feature, open examples/features.md and
preview it. See Quickstart.
In Neovim, pass options to setup(), or to lazy.nvim's opts, named like the
g:mkdp_* variables without the prefix:
{
"sammaji/markdown-preview.nvim",
-- ...
opts = {
-- "dark" or "light"; by default the page follows the system
theme = "dark",
-- a browser name, or a command with arguments; the URL is appended
browser = { "firefox", "--new-window" },
-- keep the page open when you switch to another buffer
auto_close = false,
-- a shadcn/ui or tweakcn theme
theme_css = vim.fn.expand("~/.config/nvim/mkdp-theme.css"),
preview_options = {
-- "middle", "top" or "relative"
sync_scroll_type = "top",
-- YAML front matter: "hide", "panel" or "raw"
front_matter = "panel",
},
},
}In Vim, set the variables before the plugin loads:
let g:mkdp_theme = 'dark'
let g:mkdp_browser = ['firefox', '--new-window']
let g:mkdp_auto_close = 0
let g:mkdp_preview_options = { 'sync_scroll_type': 'top' }See the configuration reference for every option, and Theming for styling the page.
The documentation is at mkdp.sammaji.com.
