toppair/peek.nvim

github github
programming-languages-supportmarkdown-and-latex
stars 494
issues 16
subscribers 2
forks 34
CREATED

2022-10-15

UPDATED

9 days ago


peek.nvim

Markdown preview plugin for Neovim

preview

:sparkles: Features

  • live update
  • synchronized scrolling
  • github-style look
  • TeX math
  • Mermaid diagrams

:battery: Requirements

:electric_plug: Installation

use({ 'toppair/peek.nvim', run = 'deno task --quiet build:fast' })

lazy.nvim

{
    "toppair/peek.nvim",
    event = { "VeryLazy" },
    build = "deno task --quiet build:fast",
    config = function()
        require("peek").setup()
        -- refer to `configuration to change defaults`
        vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {})
        vim.api.nvim_create_user_command("PeekClose", require("peek").close, {})
    end,
},

:wrench: Configuration

-- default config:
require('peek').setup({
  auto_load = true,         -- whether to automatically load preview when
                            -- entering another markdown buffer
  close_on_bdelete = true,  -- close preview window on buffer delete

  syntax = true,            -- enable syntax highlighting, affects performance

  theme = 'dark',           -- 'dark' or 'light'

  update_on_change = true,

  app = 'webview',          -- 'webview', 'browser', string or a table of strings
                            -- explained below

  filetype = { 'markdown' },-- list of filetypes to recognize as markdown

  -- relevant if update_on_change is true
  throttle_at = 200000,     -- start throttling when file exceeds this
                            -- amount of bytes in size
  throttle_time = 'auto',   -- minimum amount of time in milliseconds
                            -- that has to pass before starting new render
})

:paperclip: app option

Preview opens in a webview window by default. You can set this option to 'browser' (will use your default browser as previewer) or specify browser along with arguments:

app = 'chromium'

app = { 'chromium', '--new-window' }

Chromium based browser is recommended.

:bulb: Usage

method
open Open preview window
close Close preview window
is_open Returns true if preview window is currently open

Example command setup:

vim.api.nvim_create_user_command('PeekOpen', require('peek').open, {})
vim.api.nvim_create_user_command('PeekClose', require('peek').close, {})

The following keybinds are active when preview window is focused:

key
k scroll up
j scroll down
u scroll up half a page
d scroll down half a page
g scroll to top
G scroll to bottom

:mag: Preview window

Use your window manager to set preview window properties. Window title is Peek preview.

i3wm examples:

# do not focus preview window on open
no_focus [title="^Peek preview$"]

Use i3-msg to manipulate current layout and open preview window at desired position:

local peek = require('peek')

vim.api.nvim_create_user_command('PeekOpen', function()
  if not peek.is_open() and vim.bo[vim.api.nvim_get_current_buf()].filetype == 'markdown' then
    vim.fn.system('i3-msg split horizontal')
    peek.open()
  end
end, {})

vim.api.nvim_create_user_command('PeekClose', function()
  if peek.is_open() then
    peek.close()
    vim.fn.system('i3-msg move left')
  end
end, {})