VimTeX Documentation

repository·master·Indexed 27 days ago

https://github.com/lervag/vimtex

A modern LaTeX filetype and syntax plugin for Vim (v9.2+) and Neovim (v0.12.4+). It provides advanced features for LaTeX editing, including compilation support for latexmk, latexrun, tectonic, and arara; PDF viewing with forward search; specialized motions and text objects; and a comprehensive completion API. The plugin includes built-in support for syntax highlighting, indentation, and project management for import and subfiles packages.

Tokens
4.4K
Snippets
8
Records
30
Agent score
91%

What's inside VimTeX

  1. Explore VimTeX features

    master

    VimTeX provides a comprehensive suite of features for LaTeX editing, accessible via commands and mappings (defaulting to <localleader>l).

    Key capabilities include:

    • Compilation: Supports latexmk, latexrun, tectonic, or arara.
    • Log Parsing: Quickfix entries via internal methods or pplatex.
    • PDF Viewing: Forward search support for MuPDF, Okular, qpdfview, Skim, SumatraPDF, TeXShop, and Zathura.
    • Completion: Citations, labels, commands, filenames, glossary entries, and package/documentclass names.
    • Navigation: Table of contents, table of labels, and enhanced gf command.
    • Word Count: Integration with texcount.
    • Syntax & Folding: Improved indentation, syntax highlighting (including nested support), and folding.
    • Project Support: Support for import and subfiles packages.
  2. Understand VimTeX plugin structure

    master
    VimTeX is implemented as a filetype plugin for tex and bib filetypes. The main entry points for its functionalities are located in the ftplugin/ directory. When a LaTeX or BibTeX file is opened, these scripts ensure VimTeX is loaded and then execute vimtex#init() from autoload/vimtex.vim.
  3. Delete surrounding LaTeX content

    master

    Use the following commands to delete LaTeX structural elements while preserving their contents:

    • Commands: dsc deletes a LaTeX command but preserves its arguments and square-bracket parameters.
    • Environments: dse deletes the \begin{} and \end{} declarations of an environment without changing its contents.
    • Math Zones: ds$ deletes surrounding math zones (display math, standard environments, or inline math) without changing the math contents.
    • Delimiters: dsd deletes delimiters (e.g., (), [], {} and \left\right / \big variants) without changing the enclosed content.
  4. Toggle LaTeX commands and environments

    master

    Quickly switch between different LaTeX states using toggle commands:

    • Starred versions: Use tsc to toggle starred commands and tss to toggle starred environments (Note: tss was renamed from tse in v2.16).
    • Related environments: Use tse to toggle between related environments (e.g., itemize $\leftrightarrow$ enumerate).
    • Math modes: Use ts$ to toggle between inline math, display math, and standard math environments.
    • Delimiter modifiers: Use tsd to toggle between plain delimiters and their \left/\right versions. You can extend this list using the g:vimtex_delim_toggle_mod_list variable.
    • Fractions: Use tsf to toggle between inline fractions and \frac{}{} versions.
  5. Navigate LaTeX document structure

    master

    Use VimTeX motion commands to jump through the document structure:

    • Sections: Use ]] to jump to the next \section, \subsection, or \subsubsection. Use [[ to jump backward. For more granular control, see :help <Plug>(vimtex-][) and :help <Plug>(vimtex-[]).
    • Environments: Use ]m to jump to the next \begin{} environment and [m for the previous one. Use ]M and [M for alternative navigation (see :help <Plug>(vimtex-]M) and :help <Plug>(vimtex-[M)).
    • Math Zones: Use ]n to jump to the next math zone and [n for the previous one. Use ]N and [N for alternative navigation (see :help <Plug>(vimtex-]N) and :help <Plug>(vimtex-[N)).
    • Beamer Frames: Use ]r to jump to the next Beamer frame and [r for the previous one. Use ]R and [R for alternative navigation (see :help <Plug>(vimtex-]R) and :help <Plug>(vimtex-[R)).
    • Matching Delimiters: Use % to jump between matching delimiters, inline-math $ delimiters, and LaTeX environments.
  6. Install VimTeX with vim-plug

    master

    Add one of the following lines to your .vimrc or init.vim to install VimTeX using vim-plug. You can either use the latest version from the master branch or pin to a specific release tag.

    Plug 'lervag/vimtex'
    Plug 'lervag/vimtex', { 'tag': 'v2.15' }
  7. Install VimTeX with lazy.nvim

    master

    To install VimTeX using lazy.nvim in Neovim, add the following plugin spec.

    CRITICAL: Do not use lazy loading for VimTeX. While VimTeX is already lazy-loaded via filetype plugins and autoload mechanisms, forcing lazy loading through your plugin manager will break the inverse-search mechanism (which requires the global command :VimtexInverseSearch). Set lazy = false to ensure correct functionality.

    {
      "lervag/vimtex",
      lazy = false,     -- we don't want to lazy load VimTeX
      -- tag = "v2.15", -- uncomment to pin to a specific release
      init = function()
        -- VimTeX configuration goes here, e.g.
        vim.g.vimtex_view_method = "zathura"
      end
    }
  8. Build the VimTeX documentation website locally

    master

    The VimTeX documentation website is a web-published version of the VimTeX help (doc/vimtex.txt). You can build and host the site locally using mise commands.

    • Use mise run web-host to host the site.
    • Use mise run web-build to rebuild the pages.
    # to host the site
    mise run web-host
    
    # to rebuild the page
    mise run web-build
  9. Use VimTeX motions and text objects

    master

    VimTeX extends Vim's movement capabilities specifically for LaTeX structures.

    Motions

    • Sections: [[, [], ][, ]] move between section boundaries.
    • Environments: [m, [M, ]m, ]M move between environment boundaries.
    • Math: [n, [N, ]n, ]N move between math environment boundaries.
    • Frames: [r, [R, ]r, ]R move between frame environment boundaries.
    • Comments: [* and ]* move between comment boundaries.
    • Delimiters: % moves between matching delimiters.

    Text Objects

    • Commands: ic (inner command), ac (around command).
    • Delimiters: id (inner delimiter), ad (around delimiter).
    • Environments: ie (inner environment), ae (around environment).
    • Math: i$ (inner math), a$ (around math).
    • Sections: iP (inner section), aP (around section).
    • Items: im (inner item), am (around item).
  10. Check VimTeX requirements

    master

    VimTeX requires specific versions of Vim or Neovim:

    • Vim: version 9.2 or higher.
    • Neovim: version 0.12.4 or higher.

    If you are using older versions, do not use the latest VimTeX release; instead, pin your installation to the v2.17 tag or older.

    Certain features require external tools. For example, the default compiler backend relies on latexmk. For a full list of requirements, refer to :help vimtex-requirements in Vim/Neovim.

  11. Change surrounding LaTeX content

    master

    Use the following commands to modify the type of LaTeX element surrounding your cursor without changing the content itself:

    • Commands: csc changes a LaTeX command while preserving its arguments.
    • Environments: cse changes the type of a LaTeX environment (e.g., switching from itemize to enumerate).
    • Math Zones: cs$ changes the type of math zone (e.g., switching between inline math, display math, and standard math environments).
    • Delimiters: csd changes delimiters (e.g., switching between () and []) and is smart enough to preserve \left\right or \big modifiers.