Skip to content

Instantly share code, notes, and snippets.

@jecolasurdo
Last active April 9, 2026 01:38
Show Gist options
  • Select an option

  • Save jecolasurdo/280b6c10478d375d7b4e2b3d7c4951ec to your computer and use it in GitHub Desktop.

Select an option

Save jecolasurdo/280b6c10478d375d7b4e2b3d7c4951ec to your computer and use it in GitHub Desktop.
Neovim config: live markdown preview with auto-prompt on file open
-- Options (migrated from init.vim)
vim.opt.number = true
vim.opt.colorcolumn = "80"
vim.opt.clipboard = "unnamedplus"
vim.opt.cursorline = true
vim.opt.textwidth = 80
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Prompt to preview when opening a markdown file
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.schedule(function()
local choice = vim.fn.confirm("Open Markdown Preview?", "&Yes\n&No", 2)
if choice == 1 then
require("lazy").load({ plugins = { "markdown-preview.nvim" } })
vim.fn["mkdp#util#open_preview_page"]()
end
end)
end,
})
-- Plugins
require("lazy").setup({
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreview", "MarkdownPreviewToggle", "MarkdownPreviewStop" },
build = "cd app && npm install",
},
})

Neovim Live Markdown Preview

Whenever you open a .md file, Neovim will prompt you to open a live preview in your browser. The preview syncs to your buffer as you type.

Requirements

  • Neovim 0.12+
  • Git
  • Node.js

Setup

  1. Back up your existing config (if you have one):

    mv ~/.config/nvim/init.vim ~/.config/nvim/init.vim.bak
    
  2. Create ~/.config/nvim/init.lua with the contents of init.lua in this gist.

    The options block at the top reflects my personal settings — adjust or remove them as you like.

  3. Open Neovim — lazy.nvim will install itself and the plugin automatically on first launch.

  4. Open any .md file — you'll be prompted:

    Open Markdown Preview? [Y]es, (N)o:
    

    Press y to open a synced browser preview, n or Enter to skip.

Manual commands

Once the plugin is loaded you can also control the preview directly:

Command Action
:MarkdownPreview Open preview
:MarkdownPreviewStop Close preview
:MarkdownPreviewToggle Toggle preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment