Skip to content

Vim and Neovim

Set up Vim with VimTeX and Zathura for LaTeX on macOS, and add the Neo-tree file explorer to Neovim.

3 min readUpdated

Two setups on macOS with Homebrew: Vim (MacVim) as a LaTeX editor with VimTeX and the Zathura PDF viewer, and Neovim with the Neo-tree file explorer, installed with packer.nvim, vim-plug or lazy.nvim.

Write LaTeX with VimTeX and Zathura

Install MacVim, Zathura and MacTeX

Install MacVim, then Zathura and its Poppler PDF plugin from the Zathura tap:

Terminal window
brew install macvim
brew tap homebrew-zathura/zathura
brew install zathura --with-synctex
brew install zathura-pdf-poppler

--with-synctex builds Zathura with SyncTeX support, which lets VimTeX jump between a line in the source and the matching place in the PDF. The tap was formerly zegervdv/zathura.

Zathura only finds the PDF plugin if it is linked into Zathura’s plugin directory. The tap’s README gives this command; run it again after installing new plugins:

Terminal window
d=$(brew --prefix zathura)/lib/zathura ; mkdir -p $d ; for n in cb djvu pdf-mupdf pdf-poppler ps ; do p=$(brew --prefix zathura-$n)/lib$n.dylib ; [[ -f $p ]] && ln -s $p $d ; done

Install a TeX distribution without the GUI applications:

Terminal window
brew install --cask mactex-no-gui

Install VimTeX with vim-plug

Install vim-plug as described in its README, then add VimTeX between the call plug#begin('~/.vim/plugged') and call plug#end() lines of your .vimrc:

~/.vimrc
" https://github.com/junegunn/vim-plug
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex'
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
" these two lines are for a separate plugin: https://github.com/KeitaNakamura/tex-conceal.vim
set conceallevel=1
let g:tex_conceal='abdmg'
" Initialize plugin system
call plug#end()
  • g:tex_flavor='latex' makes Vim treat .tex files as LaTeX rather than plain TeX.
  • g:vimtex_view_method='zathura' opens the compiled PDF in Zathura.
  • g:vimtex_quickfix_mode=0 stops the quickfix window from opening on every compiler warning.
  • conceallevel and g:tex_conceal display LaTeX commands such as \alpha as the symbol they produce. They work together with tex-conceal.vim.

Reload .vimrc and install the plugins from inside Vim:

:PlugInstall

Add Neo-tree to Neovim

Install Neovim:

Terminal window
brew install neovim

Neo-tree needs three other plugins: plenary.nvim and nui.nvim are required, nvim-web-devicons is optional and adds file icons. The v3.x branch is the current stable release line. Pick one of the plugin managers below.

With packer.nvim

Note: packer.nvim has been unmaintained since August 2023, and its README recommends lazy.nvim instead. The steps still work for existing setups.

Clone packer into Neovim’s package directory:

Terminal window
git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim

Declare Neo-tree in your Lua config, usually ~/.config/nvim/init.lua:

~/.config/nvim/init.lua
require('packer').startup(function()
use {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
requires = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- optional, for file icons
"MunifTanjim/nui.nvim",
}
}
end)

Install the plugins from inside Neovim:

:PackerSync

With vim-plug

Install vim-plug for Neovim:

Terminal window
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Declare Neo-tree in your config, ~/.config/nvim/init.vim for Vimscript:

~/.config/nvim/init.vim
call plug#begin('~/.local/share/nvim/plugged')
Plug 'nvim-neo-tree/neo-tree.nvim', { 'branch': 'v3.x' }
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-tree/nvim-web-devicons' " optional, for file icons
Plug 'MunifTanjim/nui.nvim'
call plug#end()

Install the plugins from inside Neovim:

:PlugInstall

With lazy.nvim

If you use lazy.nvim, add this plugin spec (taken from the Neo-tree README):

return {
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons", -- optional, but recommended
},
lazy = false, -- neo-tree will lazily load itself
}
}

Configure and open Neo-tree

Call setup in your Lua config to change the defaults; with no options it uses the defaults:

require("neo-tree").setup({
-- your configuration here
})

Show or hide the file tree:

:Neotree toggle

References

Related notes

2 min read

ngrok

Expose a local web server on a public HTTPS address with ngrok, for webhook testing, demos and testing on real devices.

  • Developer Tools
2 min read

NetBeans

Build Apache NetBeans from source, clear the Recent Projects list and choose the JDK the IDE runs on.

  • Developer Tools
3 min read

SonarQube

Run SonarQube locally in Docker and analyse a Maven project with the SonarScanner for Maven.

  • Observability & Testing
  • Developer Tools

Type to search the whole site.