After finished setup neovim for Python, here are the tools/software that we need to setup neovim for LaTex:

You can more information on neovim installation and neovim plugin manager (vim-plug) in the previous post setup neovim for Python.

First, we add the following three plugins into our configuration file (init.vim) in our “plugin list“.

1
2
3
4
5
6
7
8
9
10
11
12
13
" Plugins List
call plug#begin(g:plugged_home)
" other plugins...
" --------- adding the following three plugins for Latex ---------
Plug 'lervag/vimtex'
Plug 'Konfekt/FastFold'
Plug 'matze/vim-tex-fold'
" other plugins...
call plug#end()

Then we can close and reopen our neovim, run :PlugInstall to install the above three plugins.

python package for pdf compilation auto refresh

In order to let our LaTex plugin vimtex refresh compiled pdf in real time, we need to install one python package:

pip install neovim-remote

In addition, if you use Adobe Reader as your pdf viewer the real time refresh will report error since Adobe Reader will put a lock on the pdf file.

Vimtex Plugin settings

After we have the plugins installed, let’s paste the following settings for vimtex into our configuration file (init.vim)

1
2
3
4
5
6
7
8
let g:tex_flavor = 'latex'
let g:tex_conceal = ''
let g:vimtex_fold_manual = 1
let g:vimtex_latexmk_continuous = 1
let g:vimtex_compiler_progname = 'nvr'
" use SumatraPDF if you are on Windows
let g:vimtex_view_method = 'skim'

Since we used ncm2 as our completion plugin for vim, here is setting that we need to register LaTex code completion source for ncm2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
" NCM2
augroup NCM2
autocmd!
" some other settings...
" uncomment this block if you use vimtex for LaTex
autocmd Filetype tex call ncm2#register_source({
\ 'name': 'vimtex',
\ 'priority': 8,
\ 'scope': ['tex'],
\ 'mark': 'tex',
\ 'word_pattern': '\w+',
\ 'complete_pattern': g:vimtex#re#ncm2,
\ 'on_complete': ['ncm2#on_complete#omni', 'vimtex#complete#omnifunc'],
\ })
augroup END

Vimtex In Action

Now suppose we have a simple .tex file showing below

And here are the commands that we would use

  • VimtexCompile: Start compiling the LaTex Code (in continuous mode since we set it above)
  • VimtexView: Open the compiled pdf using the
  • VimtexErrors: Display errors (if any) in the current file

and we can see the real-time update as we write the file.