Live Markdown preview that renders inside your terminal !
:MarkdownPreview is great, until it throws a browser window onto your desktop and your tidy
terminal workflow falls apart. This plugin hijacks the preview hand-off from
iamcco/markdown-preview.nvim and routes it into a
right-hand iTerm2 browser pane instead. Same live reload, same renderer, but minus the window juggling.
:ItermMdPreviewStop, or just closing the markdown buffer,
closes the pane and stops the preview server. No orphaned tabs, no zombie node processes.| OS | macOS 13+ |
| iTerm2 | 3.5.0+ |
| Neovim | 0.10+ |
| Dependency | iamcco/markdown-preview.nvim |
{
"Kepler2024/iTerm-preview.nvim",
dependencies = {
{ "iamcco/markdown-preview.nvim", build = "cd app && npm install" },
},
ft = "markdown",
opts = {}, -- defaults work out of the box once the iTerm profile exists
}
use {
"Kepler2024/iTerm-preview.nvim",
requires = { { "iamcco/markdown-preview.nvim", run = "cd app && npm install" } },
config = function() require("iterm-preview").setup() end,
}
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npm install' }
Plug 'Kepler2024/iTerm-preview.nvim'
" then, after plugins load:
lua require('iterm-preview').setup()
The preview pane is just an iTerm Browser-type profile. You create it once:
iTerm โ Settings โ Profiles โ + (create new profile).
Set Profile Type โ Browser.
Name it Browser (default).
Under Initial URL, paste this exact value, with no trailing space or period:
file:///tmp/iterm-preview.html
Run :checkhealth iterm-preview to confirm the profile URL matches.
First :ItermMdPreview triggers a one-time macOS Automation prompt. Click OK to let your
terminal drive iTerm.
Not sure you got step 4 right?
:checkhealth iterm-previewreads the URL your profile actually has, compares it to the one the plugin needs, and if they differ it prints the exact value to paste. A stray trailing space or period is the usual culprit behind a blank pane that never loads.
:ItermMdPreview " preview the current buffer in an iTerm split
:ItermMdPreviewStop " close the pane and stop the server
Keymaps Config:
vim.keymap.set("n", "<leader>mp", "<cmd>ItermMdPreview<cr>", { desc = "Markdown preview (iTerm)" })
vim.keymap.set("n", "<leader>ms", "<cmd>ItermMdPreviewStop<cr>", { desc = "Stop markdown preview" })
| Command | What it does |
|---|---|
:ItermMdPreview |
Open the preview in an iTerm split (the command to reach for) |
:ItermMdPreviewStop |
Close the split and stop the preview server |
:MarkdownPreview |
Alias: mkdp's own command, transparently rerouted into the split |
:MarkdownPreviewStop |
Alias: overridden so it closes the split and stops the server |
:checkhealth iterm-preview |
Diagnose platform, iTerm version, automation permission, profile wiring |
Everything below is the default; call setup() with only what you want to change.
require("iterm-preview").setup({
port = "8089", -- mkdp HTTP server port
split = {
direction = "right", -- right | left | below | above
},
auto_close = true, -- close the pane when the previewed buffer is closed
notify_level = vim.log.levels.INFO,
iterm_app = "iTerm", -- AppleScript application name
profile = "Browser", -- iTerm Browser-type profile name
filetypes = { "markdown" }, -- forwarded to g:mkdp_filetypes
bridge_html = "/tmp/iterm-preview.html", -- meta-refresh bridge; must match the profile's Custom URL
custom_script = nil, -- function(url) -> AppleScript string (full escape hatch)
})
With thanks to the projects this plugin plugs into:
If this plugin saves you some alt-tabbing, consider buying me a coffee. Thank you! โ
MIT.