VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
VimTeX is a modern Vim and Neovim filetype and syntax plugin for LaTeX files.
VimTeX requires Vim version 8.2.3995 or Neovim version 0.9.5. The requirements were updated in April 2024 after the release of VimTeX 2.15. 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.
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
).
There are a lot of methods for installing plugins. The following explains the most common and popular approaches.
Note: 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
).
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
.
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' }
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:
:help package
!/pack/foo/start
subdirectory to make sure the filetype plugin istex
filetypes.:helptags
to generate them./start/
plugin directories at&runtimepath
. This means the built in filetype plugin is:scriptnames
.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.
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 = ","
Note: 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
.
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.
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.
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:
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.
See the file VISUALS.md for screencast-style GIFs demonstrating VimTeX's core motions, text-editing commands, and text objects.
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.
.sty
and .cls
files'include'
, 'includeexpr'
, 'suffixesadd'
and'define'
, which among other things
:h include-search
and :h definition-search
gf
commandtexcount
)[[
, []
, ][
, and ]]
[m
, [M
, ]m
, and ]M
[n
, [N
, ]n
, and ]N
[r
, [R
, ]r
, and ]R
[*
and ]*
%
ic ac
Commandsid ad
Delimitersie ae
LaTeX environmentsi$ a$
Math environmentsiP aP
Sectionsim am
Itemsdsc
/dse
/ds$
/dsd
csc
/cse
/cs$
/csd
tsc
/tse
ts$
()
and \left(\right)
with tsd
tsf
\\
with tsb
]]
\left ... \right)
modifiers to surrounding delimiters with <F8>
<F7>
\cite{...}
) mapped to <cr>
:h 'foldexpr'
):h 'indentexpr'
)See the documentation for a thorough introduction to VimTeX (e.g. :h vimtex
).
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
.
The following are some alternative LaTeX plugins for Vim:
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.:
latexmk
, latexrun
, tectonic
or arara
for compilation"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.
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).
For more alternatives and more information and discussions regarding LaTeX plugins for Vim, see: