Convert Figma logo to code with AI

lervag logovimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.

5,746
394
5,746
22

Top Related Projects

Quickstart configs for Nvim LSP

1,679

An implementation of the Language Server Protocol for LaTeX

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.

Quick Overview

VimTeX is a modern and comprehensive Vim/Neovim plugin for LaTeX files. It provides features like compilation, completion, and various text objects and motions specifically designed for LaTeX documents. VimTeX aims to make writing LaTeX in Vim/Neovim more efficient and enjoyable.

Pros

  • Extensive feature set tailored for LaTeX, including syntax highlighting, compilation, and navigation
  • Highly customizable with many configuration options
  • Active development and maintenance with frequent updates
  • Seamless integration with other Vim/Neovim plugins and ecosystems

Cons

  • Steep learning curve for new users, especially those unfamiliar with Vim/Neovim
  • Can be resource-intensive on larger LaTeX projects
  • Some features may require additional external tools or dependencies

Code Examples

  1. Compiling a LaTeX document:
:VimtexCompile
  1. Toggling the table of contents:
:VimtexTocToggle
  1. Jumping to a matching delimiter:
:VimtexJumpToDelimMate

Getting Started

  1. Install VimTeX using your preferred plugin manager. For example, with vim-plug:
Plug 'lervag/vimtex'
  1. Add basic configuration to your .vimrc or init.vim:
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
  1. Open a LaTeX file and start using VimTeX commands, such as :VimtexCompile to compile your document.

Competitor Comparisons

Quickstart configs for Nvim LSP

Pros of nvim-lspconfig

  • Broader language support: Configures LSP for multiple languages, not just LaTeX
  • Integrates with Neovim's built-in LSP client for a more native experience
  • Actively maintained with frequent updates and improvements

Cons of nvim-lspconfig

  • Requires more setup and configuration compared to VimTeX's out-of-the-box experience
  • Less specialized LaTeX features and optimizations
  • Steeper learning curve for users new to LSP concepts

Code Comparison

VimTeX example:

let g:vimtex_compiler_latexmk = {
    \ 'options' : [
    \   '-pdf',
    \   '-shell-escape',
    \   '-verbose',
    \   '-file-line-error',
    \   '-synctex=1',
    \   '-interaction=nonstopmode',
    \ ],
    \}

nvim-lspconfig example:

require'lspconfig'.texlab.setup{
  settings = {
    texlab = {
      build = {
        args = { "-pdf", "-interaction=nonstopmode", "-synctex=1" },
        executable = "latexmk",
        onSave = true
      }
    }
  }
}

Both repositories serve different purposes: VimTeX is a comprehensive LaTeX plugin for Vim/Neovim, while nvim-lspconfig is a general-purpose LSP configuration helper for Neovim. VimTeX offers a more specialized LaTeX experience, while nvim-lspconfig provides broader language support through LSP integration.

1,679

An implementation of the Language Server Protocol for LaTeX

Pros of texlab

  • Language server protocol (LSP) support, enabling integration with various editors
  • More advanced language features like code completion and refactoring
  • Cross-platform compatibility (Windows, macOS, Linux)

Cons of texlab

  • Less mature and potentially less stable than vimtex
  • Smaller community and fewer contributors
  • May have a steeper learning curve for configuration

Code comparison

texlab (Rust):

pub fn build_request(&self, params: &BuildParams) -> Result<Command> {
    let mut args = vec![];
    if let Some(executable) = &self.executable {
        args.push(executable.to_string());
    }
    // ... (additional code)
}

vimtex (VimScript):

function! vimtex#compiler#latexmk#init(options) abort
  let l:compiler = deepcopy(s:compiler)
  call l:compiler.init(a:options)
  return l:compiler
endfunction

Both projects aim to enhance LaTeX editing, but they take different approaches. texlab focuses on providing a language server for LaTeX, offering advanced features and cross-editor compatibility. vimtex, on the other hand, is a comprehensive Vim plugin specifically tailored for LaTeX users in the Vim ecosystem. The choice between them depends on the user's preferred editor and desired features.

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.

Pros of LaTeX-Workshop

  • Integrated with Visual Studio Code, providing a modern, feature-rich IDE experience
  • Offers a live preview feature, allowing real-time visualization of LaTeX output
  • Includes built-in PDF viewer with synctex support

Cons of LaTeX-Workshop

  • May have a steeper learning curve for users not familiar with VS Code
  • Can be resource-intensive, especially on older hardware
  • Less customizable compared to Vim-based solutions

Code Comparison

LaTeX-Workshop (settings.json):

"latex-workshop.latex.tools": [
  {
    "name": "latexmk",
    "command": "latexmk",
    "args": [
      "-synctex=1",
      "-interaction=nonstopmode",
      "-file-line-error",
      "-pdf",
      "%DOC%"
    ]
  }
]

VimTeX (.vimrc):

let g:vimtex_compiler_method = 'latexmk'
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_mode = 0
let g:tex_flavor = 'latex'

Both plugins offer powerful LaTeX editing capabilities, with LaTeX-Workshop providing a more modern, GUI-based experience, while VimTeX caters to users who prefer the efficiency and customizability of Vim.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

VimTeX

VimTeX is a modern Vim and Neovim filetype and syntax plugin for LaTeX files.

Gitter CI tests Donate

Table of contents

Requirements

VimTeX requires Vim version 9.1 or Neovim version 0.10. The requirements were updated in January 2025 after the release of VimTeX 2.16. If you are stuck on older versions of Vim or Neovim, then you should not use the most recent version of VimTeX, but instead remain at the v2.15 tag (or older).

Some features require external tools. For example, the default compiler backend relies on latexmk. Users are encouraged to read the requirements section in the documentation (:h vimtex-requirements).

Installation

There are a lot of methods for installing plugins. The following explains the most common and popular approaches.

[!WARNING]

Many plugin managers provide mechanisms to lazy load plugins. Please don't use this for VimTeX! VimTeX is already lazy loaded by virtue of being a filetype plugin and by using the autoload mechanisms. There is therefore nothing to gain by forcing VimTeX to lazily load through the plugin manager. In fact, doing it will break the inverse-search mechanism, which relies on a global command (:VimtexInverseSearch).

lazy.nvim

In Neovim, lazy.nvim is probably the most popular plugin manger. To install VimTeX, add a plugin spec similar to this:

{
  "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
}

VimTeX is mostly implemented with Vimscript and is configured with the classical vimscript variable convention like g:vimtex_OPTION_NAME. Nowadays, Neovim is often configured with Lua, thus some users may be interested in reading :help lua-vimscript.

vim-plug

If you use vim-plug, then add one of the following lines to your configuration. The first will use the latest versions from the master branch, whereas the second will pin to a release tag.

Plug 'lervag/vimtex'
Plug 'lervag/vimtex', { 'tag': 'v2.15' }

Other

There are many other plugin managers out there. They are typically well documented, and it should be straightforward to extrapolate the above snippets.

[!NOTE]

If you use the built-in package feature, then:

  • Make sure to read and understand the package feature: :help package!
  • Use the /pack/foo/start subdirectory to make sure the filetype plugin is automatically loaded for the tex filetypes.
  • Helptags are not generated automatically. Run :helptags to generate them.
  • Please note that by default Vim puts custom /start/ plugin directories at the end of the &runtimepath. This means the built in filetype plugin is loaded, which prevents VimTeX from loading. See #1413 for two suggested solutions to this. To see which scripts are loaded and in which order, use :scriptnames.
  • For more information on how to use the Vim native package solution, see here and here.

Configuration

After installing VimTeX, you should edit your .vimrc file or init.vim file to configure VimTeX to your liking. Users should read the documentation to learn the various configuration possibilities, but the below is a simple overview of some of the main aspects.

[!CAUTION]

PLEASE don't just copy this without reading the comments!

" This is necessary for VimTeX to load properly. The "indent" is optional.
" Note: Most plugin managers will do this automatically!
filetype plugin indent on

" This enables Vim's and neovim's syntax-related features. Without this, some
" VimTeX features will not work (see ":help vimtex-requirements" for more
" info).
" Note: Most plugin managers will do this automatically!
syntax enable

" Viewer options: One may configure the viewer either by specifying a built-in
" viewer method:
let g:vimtex_view_method = 'zathura'

" Or with a generic interface:
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'

" VimTeX uses latexmk as the default compiler backend. If you use it, which is
" strongly recommended, you probably don't need to configure anything. If you
" want another compiler backend, you can change it as follows. The list of
" supported backends and further explanation is provided in the documentation,
" see ":help vimtex-compiler".
let g:vimtex_compiler_method = 'latexrun'

" Most VimTeX mappings rely on localleader and this can be changed with the
" following line. The default is usually fine and is the symbol "\".
let maplocalleader = ","

Quick Start

The following video shows how to use VimTeX's main features (credits: @DustyTopology from #1946). The example LaTeX file used in the video is available under test/example-quick-start/main.tex and it may be instructive to copy the file and play with it to learn some of these basic functions.

https://user-images.githubusercontent.com/66584581/119213849-1b7d4080-ba77-11eb-8a31-7ff7b9a4a020.mp4

[!TIP]

If the compiler or the viewer doesn't start properly, one may type <localleader>li to view the system commands that were executed to start them. To inspect the compiler output, use <localleader>lo.

Tutorial

Both new and experienced users are encouraged to read the excellent guide by @ejmastnak: Getting started with the VimTeX plugin. The guide covers all the fundamentals of setting up a VimTeX-based LaTeX workflow, including usage of the VimTeX plugin, compilation, setting up forward and inverse search with a PDF reader, and Vimscript tools for user-specific customization.

Documentation

Users are of course strongly encouraged to read the documentation, at least the introduction, to learn about the different features and possibilities provided by VimTeX (see :h vimtex). Advanced users and potential developers may also be interested in reading the supplementary documents:

Screenshots

Here is an example of the syntax highlighting provided by VimTeX. The conceal feature is active on the right-hand side split. The example is made by @DustyTopology with the vim-colors-xcode colorscheme with some minor adjustments described here.

Syntax example

GIFs

See the file VISUALS.md for screencast-style GIFs demonstrating VimTeX's core motions, text-editing commands, and text objects.

Features

Below is a list of features offered by VimTeX. The features are accessible as both commands and mappings. The mappings generally start with <localleader>l, but if desired one can disable default mappings to define custom mappings. Nearly all features are enabled by default, but each feature may be disabled if desired. The two exceptions are code folding and formating, which are disabled by default and must be manually enabled.

  • Document compilation with latexmk, latexrun, tectonic, or arara
  • LaTeX log parsing for quickfix entries using
  • Compilation of selected part of document
  • Support for several PDF viewers with forward search
  • Completion of
    • citations
    • labels
    • commands
    • file names for figures, input/include, includepdf, includestandalone
    • glossary entries
    • package and documentclass names based on available .sty and .cls files
  • Document navigation through
    • table of contents
    • table of labels
    • proper settings for 'include', 'includeexpr', 'suffixesadd' and 'define', which among other things
      • allow :h include-search and :h definition-search
      • give enhanced gf command
  • Easy access to (online) documentation of packages
  • Word count (through texcount)
  • Motions (link to GIF demonstrations)
    • Move between section boundaries with [[, [], ][, and ]]
    • Move between environment boundaries with [m, [M, ]m, and ]M
    • Move between math environment boundaries with [n, [N, ]n, and ]N
    • Move between frame environment boundaries with [r, [R, ]r, and ]R
    • Move between comment boundaries with [* and ]*
    • Move between matching delimiters with %
  • Text objects (link to GIF demonstrations)
    • ic ac Commands
    • id ad Delimiters
    • ie ae LaTeX environments
    • i$ a$ Math environments
    • iP aP Sections
    • im am Items
  • Other mappings (link to GIF demonstrations)
    • Delete the surrounding command, environment or delimiter with dsc/dse/ds$/dsd
    • Change the surrounding command, environment or delimiter with csc/cse/cs$/csd
    • Toggle between complementary environments with tse (see v2.16 release notes)
    • Toggle starred command or environment with tsc/tss
    • Toggle inline and displaymath with ts$
    • Toggle between e.g. () and \left(\right) with tsd
    • Toggle (inline) fractions with tsf
    • Toggle line-break macro \\ with tsb
    • Close the current environment/delimiter in insert mode with ]]
    • Add \left ... \right) modifiers to surrounding delimiters with <F8>
    • Insert new command with <F7>
    • Convenient insert mode mappings for faster typing of e.g. maths
    • Context menu on citations (e.g. \cite{...}) mapped to <cr>
  • Improved folding (:h 'foldexpr')
  • Improved indentation (:h 'indentexpr')
  • Syntax highlighting
    • A consistent core syntax specification
    • General syntax highlighting for several popular LaTeX packages
    • Nested syntax highlighting for several popular LaTeX packages
    • Highlight matching delimiters
  • Support for multi-file project packages

See the documentation for a thorough introduction to VimTeX (e.g. :h vimtex).

Other relevant plugins

Even though VimTeX provides a lot of nice features for working with LaTeX documents, there are several features that are better served by other, dedicated plugins. For a more detailed listing of these, please see :help vimtex-and-friends.

Linting and syntax checking

Snippets and templates

Tag navigation

Alternatives

The following are some alternative LaTeX plugins for Vim:

  • LaTeX-Suite

    The main difference between VimTeX and LaTeX-Suite (aka vim-latex) is probably that VimTeX does not try to implement a full fledged IDE for LaTeX inside Vim. E.g.:

    • VimTeX does not provide a full snippet feature, because this is better handled by UltiSnips or neosnippet or similar snippet engines.
    • VimTeX builds upon Vim principles: It provides text objects for environments, inline math, it provides motions for sections and paragraphs
    • VimTeX uses latexmk, latexrun, tectonic or arara for compilation with a callback feature to get instant feedback on compilation errors
    • VimTeX is very modular: if you don't like a feature, you can turn it off.
  • TexMagic.nvim

    "A simple, lightweight Neovim plugin that facilitates LaTeX build engine selection via magic comments. It is designed with the TexLab LSP server's build functionality in mind, which at the time of this plugin's inception had to be specified in init.lua/init.vim and could not be set on a by-project basis."

    This plugin should be combined with the TexLab LSP server, and it only works on neovim.

  • LaTeX-Box

    VimTeX currently has most of the features of LaTeX-Box, as well as some additional ones. See here for a relatively complete list of features.

    One particular feature that LaTeX-Box has but VimTeX misses, is the ability to do single-shot compilation with callback. This functionality was removed because it adds a lot of complexity for relatively little gain (IMHO).

  • AutomaticTexPlugin

  • vim-latex-live-preview

For more alternatives and more information and discussions regarding LaTeX plugins for Vim, see: