WYSIWYG code screenshots from Neovim (TOhtml -> PNG)
Create images from the current buffer or a visual selection - with the same colorscheme, highlights, and diagnostics you see in Neovim.
nvim-web-devicons)
{
"glyccogen/imprint.nvim",
cmd = "Imprint",
dependencies = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons in the titlebar
},
config = function()
require("imprint").setup({})
end,
}
use {
"glyccogen/imprint.nvim",
cmd = "Imprint",
requires = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons in the titlebar
},
config = function()
require("imprint").setup({})
end
}
pip and venvnvim-web-devicons for file icons in the titlebarxclip (X11)wl-copy (Wayland)osascript (macOS):TOhtml command (Lua tohtml module, Neovim 0.10+), which converts the current buffer or visual selection into a temporary html file.py/render.py renders html file using Playwright. It launches a headless Chromium browser, takes a screenshot of the rendered code block.--clipboard-only is not set. If copy_to_clipboard is enabled, the image is copied to the system clipboard.[!WARNING] the Python/Playwright step is isolated in a dedicated virtual environment, so it does not interfere with your system Python packages, and Playwright with Chromium is downloaded only once on first use.
require('imprint').setup({
-- default title used for the window header
-- fallback if no title is provided
default_title = nil,
-- when true, prompt for a title if none was provided and --no-title is not set
required_title_by_default = true,
-- copy the generated image to the clipboard after saving
copy_to_clipboard = false,
-- output directory for saved screenshots
-- when nil, saves to the current file's directory
output_dir = nil,
-- hex-code for the background outside the code window
background = "#A5A6F6",
-- line number visibility
-- true: current settings
-- false: no line numbers
-- "absolute": absolute line numbers
-- "absolute_from_1": absolute line numbers starting from 1 in the image
line_numbers = "absolute_from_1",
-- highlight the line number the cursor is on
highlight_current_line = false,
-- show diagnostic signs highlights
diagnostics_on = false,
-- show a file icon in the titlebar
-- depends on nvim-web-devicons
icons_on = true,
})
create a screenshot from the current buffer or a selected range.
:['<,'>]Imprint [options] [title]
-c, --clipboard-only - copy the image to the clipboard and do not save it to disk-o, --open - open the generated image--no-title - do not prompt for a title when none is providedtitle - optional title for the window headerUsing -c (--clipboard_only) and -o (--open) together: the temporary image opens with default image viewer and it will not be deleted.
Playwright install fails on first run
imprint.nvim installs Chromium for Playwright. If step fails, system may be missing OS packages Playwright needs. In that case, run:
NVIM_DATA_DIR="$(nvim --headless -u NONE --cmd 'lua io.write(vim.fn.stdpath("data"))' +qa)"
"$NVIM_DATA_DIR/imprint.nvim/venv/bin/playwright" install --with-deps chromium