Mermaid in Neovim: Preview Diagrams and Fix Rendering

To preview Mermaid in Neovim, use a Markdown preview plugin that includes Mermaid, such as markdown-preview.nvim. Open a .md file and run :MarkdownPreview. The diagram renders in a browser beside Neovim; syntax highlighting in the editor alone does not render it.

If you only need to inspect one document, save it and open the file in mdview.io. For a preview that follows your edits, configure the plugin below.

Two Plugins With Similar Names

iamcco/markdown-preview.nvim and selimacerbas/markdown-preview.nvim are different projects. The latter has been renamed to mdkite.nvim. Use the configuration and commands for the project you installed.

Project Setup module Start preview
iamcco/markdown-preview.nvim mkdp settings :MarkdownPreview
selimacerbas/mdkite.nvim require("mdkite").setup() :MdKite

For current mdkite releases, a minimal lazy.nvim entry is:

{
  "selimacerbas/mdkite.nvim",
  dependencies = { "selimacerbas/kitehost.nvim" },
  config = function()
    require("mdkite").setup({})
  end,
}

Install compatible releases of both plugins, run :Lazy sync, reopen your file, then use :MdKite. Stop with :MdKite stop. The current project requires Neovim 0.10 or newer and uses a Lua preview server; browser libraries load from CDNs. It also supports standalone .mmd files. Older markdown-preview.nvim instructions use different module, dependency and command names: consult the upstream upgrade guide before changing an existing setup.

The remaining installation example below is specifically for iamcco's plugin. Avoid enabling both plugins while diagnosing preview problems.

Install iamcco/markdown-preview.nvim

If you already use lazy.nvim, add this plugin specification to your existing plugin list:

{
  "iamcco/markdown-preview.nvim",
  cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
  ft = { "markdown" },
  build = function()
    vim.fn["mkdp#util#install"]()
  end,
}

This uses the plugin's prebuilt installation route. Run :Lazy sync, let installation finish, and reopen your Markdown file. If the binary installation fails on your platform, use the Node.js installation alternative in the plugin installation instructions.

Do not replace your entire Neovim configuration with this snippet. It is one entry in a plugin list, and its location depends on how your configuration loads lazy.nvim.

Check a Minimal Markdown File

Save the following as diagram-test.md. Keep the opening and closing fences: the plugin needs them to distinguish a diagram from ordinary text.

# Release workflow

```mermaid
graph LR
  Draft[Draft] --> Review[Review]
  Review --> Publish[Publish]
```

Open the file, then run:

:MarkdownPreview

The browser should show three connected boxes below the heading. Change Review to Approve and check that the preview updates. Stop it with :MarkdownPreviewStop when you are finished.

When Mermaid Does Not Render

Symptom What to check
MarkdownPreview is not an editor command Confirm the plugin installed and loaded; inspect its status in lazy.nvim.
The file opens as plain text Run :set filetype?. A .md buffer should normally report markdown.
The preview shows a code block Check the fence label is exactly mermaid, then try the complete test file above.
A simple diagram works but the real one fails Reduce the failing diagram and check syntax or Mermaid version differences.
No browser window opens Check browser availability and the plugin's browser settings, especially under SSH or WSL.

To diagnose filetype detection temporarily, run :set filetype=markdown. If that fixes preview, correct your file naming or filetype configuration rather than changing the document's diagram syntax.

For a browser that does not open automatically, set vim.g.mkdp_echo_preview_url = 1 in your configuration and retry. Remote Neovim sessions need a reachable preview address and a browser on the machine where you want to view it; they do not automatically share localhost with your laptop.

Standalone Mermaid Files and Terminal Previews

A .mmd file contains diagram source without Markdown fences. Current mdkite releases support it directly; check the installed plugin before applying Markdown-buffer instructions. For a repeatable image export, use the Mermaid CLI workflow.

A terminal Markdown renderer can make prose and code easier to read, but its treatment of Mermaid depends on that tool. Test diagram support separately from text formatting. See terminal Markdown reader options if your main task is reading READMEs in the shell.

Render Inside Neovim With diagram.nvim

For images inside the editor, 3rd/diagram.nvim is a different route from a browser preview. Its Mermaid renderer runs mmdc; image.nvim displays the resulting image. Check each layer separately:

  1. Configure image.nvim and confirm its image display works in your terminal. Its setup includes ImageMagick and a supported graphics backend, such as Kitty. A working browser preview does not test this layer.
  2. Install the official Mermaid CLI. In the same Neovim session, run :lua print(vim.fn.executable("mmdc")). A result of 1 means Neovim can find the executable; it does not prove rendering succeeds.
  3. After image.nvim works, add this entry to your existing lazy.nvim plugin list:
{
  "3rd/diagram.nvim",
  dependencies = { "3rd/image.nvim" },
  opts = {},
}
  1. Run :Lazy sync, reopen diagram-test.md from the example above, and leave insert mode after an edit. The default rendering events include InsertLeave, BufWinEnter, and TextChanged.

This entry assumes image.nvim already has a working configuration; declaring a dependency does not configure your terminal or install system packages. Keep that configuration in its own plugin entry.

If no diagram appears, isolate the failing layer. An executable check returning 0 points to Neovim's PATH. If mmdc is found, try the standalone flow.mmd conversion in the CLI guide. If the image renders there, check image.nvim's backend and terminal setup before rewriting valid Mermaid source. Use the browser-preview route when inline terminal graphics are unavailable.

Check the Document Before Sharing

After the small example works, check your actual document's tables, local images, and every diagram. A plugin preview and the destination where you publish can use different Mermaid versions. Keep the original source and compare the same small failing block in each renderer; the Mermaid compatibility guide explains that failure pattern.

For a document review outside the editor, save your file and open it in mdview.io. You can inspect the rendered document before deciding whether to export or share it.