A Neovim plugin for previewing Markdown files using gh-markdown-preview. This plugin provides a seamless integration with GitHub's official Markdown API to preview your Markdown files with the exact same styling as GitHub.
- GitHub-style Markdown rendering
- Live reload on file save
- Automatic browser opening
- Process lifecycle management (auto-cleanup on Neovim exit)
- Support for dark/light mode
- Customizable port and options
- Built with modern Neovim APIs (
vim.system)
- Neovim 0.10+
- GitHub CLI (
gh) - gh-markdown-preview extension
gh extension install yusukebe/gh-markdown-previewUsing lazy.nvim (recommended):
-- Simple setup
{
'babarot/markdown-preview.nvim',
ft = 'markdown',
}
-- Or with custom configuration
{
'babarot/markdown-preview.nvim',
ft = 'markdown',
opts = {
-- Only needed if you've renamed/aliased the gh extension command
-- gh_cmd = 'md', -- e.g., if you aliased 'gh markdown-preview' to 'gh md'
},
keys = {
{ '<leader>mp', '<cmd>MarkdownPreview<cr>', desc = 'Markdown Preview' },
{ '<leader>ms', '<cmd>MarkdownPreviewStop<cr>', desc = 'Markdown Preview Stop' },
{ '<leader>mt', '<cmd>MarkdownPreviewToggle<cr>', desc = 'Markdown Preview Toggle' },
},
}Using packer.nvim:
use {
'babarot/markdown-preview.nvim',
ft = 'markdown',
}Using vim-plug:
Plug 'babarot/markdown-preview.nvim', { 'for': 'markdown' }Start the markdown preview server for the current buffer.
Options:
--dark-modeor-d: Force dark mode--light-modeor-l: Force light mode--disable-auto-open: Disable automatic browser opening--port=<number>: Specify custom port (default: 3333)
Examples:
:MarkdownPreview
:MarkdownPreview --dark-mode
:MarkdownPreview --port=8080
:MarkdownPreview --dark-mode --disable-auto-openStop the markdown preview server.
Toggle the markdown preview server. Accepts the same options as :MarkdownPreview.
By default, the plugin works out of the box with no configuration needed. It uses gh markdown-preview command.
If you've renamed or aliased the gh extension command, you can configure it:
{
'babarot/markdown-preview.nvim',
ft = 'markdown',
opts = {
gh_cmd = 'your-custom-alias', -- Only needed if you've aliased the command
},
}require('markdown-preview').setup({
gh_cmd = 'your-custom-alias', -- Default: 'markdown-preview'
})Note: Most users don't need to configure anything. Only set gh_cmd if you've created a custom alias for the gh extension.
You can also use the Lua API directly:
local markdown_preview = require('markdown-preview')
-- Configure first (optional)
markdown_preview.setup({
gh_cmd = 'markdown-preview', -- or 'md' if you've aliased it to the short version
})
-- Start preview
markdown_preview.start()
-- Start with options
markdown_preview.start({
dark_mode = true,
port = 8080,
disable_auto_open = false,
})
-- Stop preview
markdown_preview.stop()
-- Toggle preview
markdown_preview.toggle()
-- Check if preview is running
if markdown_preview.is_running() then
print('Preview is running')
end- When you run
:MarkdownPreview, the plugin starts agh markdown-previewserver process usingvim.system() - The server watches your Markdown file and automatically reloads the preview when you save changes
- Your default browser opens automatically (unless
--disable-auto-openis used) - The preview server runs in the background and is automatically stopped when you exit Neovim
Install GitHub CLI from https://cli.github.com/
Install the extension:
gh extension install yusukebe/gh-markdown-previewUpdate your Neovim to version 0.10 or later:
# macOS
brew upgrade neovim
# Or download from https://github.com/neovim/neovim/releasesSpecify a different port:
:MarkdownPreview --port=8080MIT