chomosuke/typst-preview.nvim

Lua

Low latency typst preview for Neovim

luaneovimneovim-luaneovim-pluginnvimnvim-luanvim-plugin
Star 增长趋势
Star
1k
Forks
57
周增长
Issues
12
5001k
2023年11月2024年10月2025年9月2026年9月
README
Logo that represents the split screen workflow: an eye with NeoVim colours on one half (coding) and black and white on the other (preview); Typst’s logo is in the iris

✨ Typst Preview for Neovim ✨

The Neovim plugin for Myriad-Dreamin/tinymist.

https://github.com/chomosuke/typst-preview.nvim/assets/38484873/9f8ecf0f-aa1c-4edb-85a9-96a8005e8f25

💪 Features

  • Low latency preview: preview your document instantly on type. The incremental rendering technique makes the preview latency as low as possible.
  • Cross jump between code and preview. You can click on the preview to jump to the corresponding code location and have the preview follow your cursor in Neovim.

📦 Installation

Dependencies

  • curl

Lazy.nvim:

{
  'chomosuke/typst-preview.nvim',
  lazy = false, -- or ft = 'typst'
  version = '1.*',
  opts = {}, -- lazy.nvim will implicitly calls `setup {}`
}

Packer.nvim:

use {
  'chomosuke/typst-preview.nvim',
  tag = 'v1.*',
  config = function()
    require 'typst-preview'.setup {}
  end,
}

vim-plug:

Plug 'chomosuke/typst-preview.nvim', {'tag': 'v1.*'}

Note: You can pin typst's minor version by pinning the minor version of this plugin, i.e., v1.1.* instead of v1.*.

🚀 Usage

Commands / Functions:

  • :TypstPreviewUpdate or require 'typst-preview'.update():
    • Download the necessary binaries to vim.fn.fnamemodify(vim.fn.stdpath 'data' .. '/typst-preview/', ':p').
    • This must be run before any other commands can be run. It is implicitly ran when calling setup {}.
  • :TypstPreview:
    • Start the preview. Optionally, the desired preview mode can be specified: :TypstPreview document (default) or :TypstPreview slide for slide mode.
  • :TypstPreviewStop:
    • Stop the preview.
  • :TypstPreviewToggle:
    • Toggle the preview.
  • :TypstPreviewFollowCursor or require 'typst-preview'.set_follow_cursor(true):
    • Scroll preview as cursor moves.
    • This is on by default.
  • :TypstPreviewNoFollowCursor or require 'typst-preview'.set_follow_cursor(false):
    • Don't scroll preview as cursor moves.
  • :TypstPreviewFollowCursorToggle or require 'typst-preview'.set_follow_cursor(not init.get_follow_cursor()).
  • :TypstPreviewSyncCursor or require 'typst-preview'.sync_with_cursor():
    • Scroll preview to the current cursor position. This can be used in combination with :TypstPreviewNoFollowCursor so that the preview only scroll to the current cursor position when you want it to.

⚙️ Configuration

This plugin should work out of the box with no configuration. However, calling setup() is required to ensure that the binaries that the plugin depends on are downloaded and up to date.

Default

require 'typst-preview'.setup {
  -- Setting this true will enable logging debug information to
  -- `vim.fn.stdpath 'data' .. '/typst-preview/log.txt'`
  debug = false,

  -- Custom format string to open the output link provided with %s
  -- Example: open_cmd = 'firefox %s -P typst-preview --class typst-preview'
  open_cmd = nil,

  -- Custom port to open the preview server. Default is random.
  -- Example: port = 8000
  port = 0,

  -- Custom host to bind the preview server to.
  -- Note that '0.0.0.0' is not supported and [won't be](https://github.com/Myriad-Dreamin/tinymist/issues/2105)
  -- Example: host = '192.168.0.10'
  host = '127.0.0.1',

  -- Setting this to 'always' will invert black and white in the preview
  -- Setting this to 'auto' will invert depending if the browser has enable
  -- dark mode
  -- Setting this to '{"rest": "<option>","image": "<option>"}' will apply
  -- your choice of color inversion to images and everything else
  -- separately.
  invert_colors = 'never',

  -- Only render the visible portion of the document.
  -- Improves performance significantly for large documents.
  -- Disable if you experience rendering issues.
  partial_rendering = true,

  -- Whether the preview will follow the cursor in the source file
  follow_cursor = true,

  -- Provide the path to binaries for dependencies.
  -- Setting this will skip the download of the binary by the plugin.
  -- Warning: Be aware that your version might be older than the one
  -- required.
  dependencies_bin = {
    tinymist = nil,
    websocat = nil
  },

  -- A list of extra arguments (or nil) to be passed to previewer.
  -- For example, extra_args = { "--input=ver=draft", "--ignore-system-fonts" }
  extra_args = nil,

  -- This function will be called to determine the root of the typst project
  get_root = function(path_of_main_file)
    local root = os.getenv 'TYPST_ROOT'
    if root then
      return root
    end

    -- Look for a project marker so imports from parent dirs stay inside root
    local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
    local found = vim.fs.find({ 'typst.toml', '.git' }, { path = main_dir, upward = true })
    if #found > 0 then
      return vim.fs.dirname(found[1])
    end

    return main_dir
  end,

  -- This function will be called to determine the main file of the typst
  -- project.
  get_main_file = function(path_of_buffer)
    return path_of_buffer
  end,
}

Use tinymist installed from Mason

Set dependencies_bin option to dependencies_bin = { tinymist = 'tinymist' } or, on Windows dependencies_bin = { tinymist = 'tinymist.cmd' } should point towards the Mason installation of tinymist.

❓ Comparison with other tools

The author of Enter-tainer/typst-preview wrote a good comparison here.

  • niuiic/typst-preview.nvim: Since niuiic/typst-preview.nvim uses typst-lsp, it has similar advantages and disadvantages of typst-lsp mentioned here:
    • Higher latency due to the PDF reader having a delay.
    • Does not support cross jump between code and preview.

💻 Contribution

All PRs are welcome.

Credit

This plugin wouldn't be possible without the work of Enter-tainer/typst-preview and Myriad-Dreamin/tinymist. If you like this plugin enough to star it, please consider starring Enter-tainer/typst-preview and Myriad-Dreamin/tinymist as well.

相关仓库
neovim/neovim

Vim-fork focused on extensibility and usability

Vim ScriptlibraryOtherneovimc
neovim.io
102.2k7.1k
coolsnowwolf/lede

Lean's LEDE source

COtherledelua
31.6k19.2k
NvChad/NvChad

Blazing fast Neovim framework providing solid defaults and a beautiful UI, enhancing your neovim experience.

LuaGNU General Public License v3.0nvimneovim
nvchad.com
28.5k2.2k
nvim-telescope/telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.

LuaMIT Licenseneovimlua
19.8k967
LunarVim/LunarVim

🌙 LunarVim is an IDE layer for Neovim. Completely free and community driven.

LuaGNU General Public License v3.0neovimvim
lunarvim.org
19.3k1.5k
cocos2d/cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.

C++cocos2dcocos2d-x
cocos.com/en/cocos2d-x
19.2k7k
Hammerspoon/hammerspoon

Staggeringly powerful macOS desktop automation with Lua

Objective-CappMIT Licensemacosobjective-c
hammerspoon.org
16.1k717
AstroNvim/AstroNvim

AstroNvim is an aesthetic and feature-rich neovim config that is extensible and easy to use with a great set of plugins

LuaGNU General Public License v3.0vimlua
astronvim.com
14.4k943
spotify/annoy

Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk

C++libraryApache License 2.0c-plus-pluspython
14.3k1.2k
dense-analysis/ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support

Vim ScriptBSD 2-Clause "Simplified" Licenselintervim
14k1.5k
luanti-org/luanti

Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation

C++Otherc-plus-plusvoxel
luanti.org
13.6k2.4k
nmap/nmap

Nmap - the Network Mapper. Github mirror of official SVN repository.

COtherc-plus-pluslua
svn.nmap.org
13.5k2.9k