Skip to content

Instantly share code, notes, and snippets.

@skulumani
Last active September 23, 2023 02:12
Show Gist options
  • Save skulumani/7ea00478c63193a832a6d3f2e661a536 to your computer and use it in GitHub Desktop.
Save skulumani/7ea00478c63193a832a6d3f2e661a536 to your computer and use it in GitHub Desktop.
A minimal vimrc setup for LaTeX on mac and linux

Vim configuration

You can spend lots of time getting vim setup to your liking, and probably never finish customizing. My suggestion is to start small and stick to the basics before going crazy with plugins. While I've included some plugins, the hope is that you can easily get started with LaTeX with a minimal of effort and/or Googling.

Here is a small section of some of the things I've figured out to have vim working for editing LaTeX files easily.

  1. Copy the file below to a file vimrc and start vim vim -u vimrc to use the file. After all your customization if you are happy then save your configuration to ~/.vimrc.

  2. You can then start vim and install the plugins using the command :PlugInstall

  3. Choose a colorscheme you like with :colorscheme <tab> to see all the options. Once you find one you like just put that command into the vimrc

  4. Setting up vimtex to work with a PDF viewer is a little complicated but I have some of the details already included. You don't actually need anything extra to handle editing LaTeX documents.

In another terminal window just run latexmk -pdf -pvc article.tex to have it continuosly compile your document. Then whenever you save your tex file, it'll compile. In fact, vimtex is basically doing this from within vim.

On a Mac, the vimtex plugin seems to work best with Skim in my view. Note, there is some setup required to enable forward/backward search using synctex.

Other useful tips

  1. You use the escape key all the time in vim. So it's best to stick it someplace easily to access. I remap the CapsLock key to Escape, since no one ever uses CapsLock

Add the following to your .bashrc or .zshrc file on Ubuntu

setxkbmap -option "caps:escape"

On Mac OSX you can look in the System Preferences > Keyboard > Modifier Keys (bottom of screen)

Documentation

" -----------------------------------------------------------------------------
" GENERAL SETTINGS FOR EVERYONE
" ----------------------------------------------------------------------------
filetype plugin indent on
set nocompatible
set autoindent
set nomodeline " disable modeline vulnerability
" text encoding
set encoding=utf8
" use 4 spaces for tabs
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround
set backspace =indent,eol,start
set hidden
set laststatus =2
" Set linenumbers
set number
set relativenumber
set wrap
" column ruler at 100
set ruler
set colorcolumn=80
" Highlight searching
set incsearch
set showmatch
set hlsearch
set ignorecase
set smartcase
if has("nvim")
set inccommand="nosplit"
endif
set autoread " autoread files
set mouse=a " use mouse for scroll or window size
" -----------------------------------------------------------------------------
" PLUGIN SETUP
" ----------------------------------------------------------------------------
" Autoload vim plug if not already there
if has("nvim")
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" autocmd VimEnter * PlugInstall
endif
else
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" autocmd VimEnter * PlugInstall
endif
endif
" All the plugins are listed here
if has('nvim')
call plug#begin('~/.config/nvim/plug.vim')
else
call plug#begin('~/.vim/plug.vim')
endif
" Productivity
Plug 'junegunn/vim-plug'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'scrooloose/nerdtree', { 'on' : 'NERDTreeToggle' }
Plug 'rafi/awesome-vim-colorschemes'
" Programming plugins
Plug 'lervag/vimtex'
call plug#end() " start all the plugins above
" -----------------------------------------------------------------------------
" VIMTEX OPTIONS
" ----------------------------------------------------------------------------
if has('unix')
if has('mac')
let g:vimtex_view_method = "skim"
let g:vimtex_view_general_viewer
\ = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
" This adds a callback hook that updates Skim after compilation
let g:vimtex_compiler_callback_hooks = ['UpdateSkim']
function! UpdateSkim(status)
if !a:status | return | endif
let l:out = b:vimtex.out()
let l:tex = expand('%:p')
let l:cmd = [g:vimtex_view_general_viewer, '-r']
if !empty(system('pgrep Skim'))
call extend(l:cmd, ['-g'])
endif
if has('nvim')
call jobstart(l:cmd + [line('.'), l:out, l:tex])
elseif has('job')
call job_start(l:cmd + [line('.'), l:out, l:tex])
else
call system(join(l:cmd + [line('.'), shellescape(l:out), shellescape(l:tex)], ' '))
endif
endfunction
else
let g:latex_view_general_viewer = "zathura"
let g:vimtex_view_method = "zathura"
endif
elseif has('win32')
endif
let g:tex_flavor = "latex"
let g:vimtex_quickfix_open_on_warning = 0
let g:vimtex_quickfix_mode = 2
if has('nvim')
let g:vimtex_compiler_progname = 'nvr'
endif
" One of the neosnippet plugins will conceal symbols in LaTeX which is
" confusing
let g:tex_conceal = ""
" Can hide specifc warning messages from the quickfix window
" Quickfix with Neovim is broken or something
" https://github.com/lervag/vimtex/issues/773
let g:vimtex_quickfix_latexlog = {
\ 'default' : 1,
\ 'fix_paths' : 0,
\ 'general' : 1,
\ 'references' : 1,
\ 'overfull' : 1,
\ 'underfull' : 1,
\ 'font' : 1,
\ 'packages' : {
\ 'default' : 1,
\ 'natbib' : 1,
\ 'biblatex' : 1,
\ 'babel' : 1,
\ 'hyperref' : 1,
\ 'scrreprt' : 1,
\ 'fixltx2e' : 1,
\ 'titlesec' : 1,
\ },
\}
" -----------------------------------------------------------------------------
" APPEARANCE
" ----------------------------------------------------------------------------
" set guifont=Sauce\ Code\ Pro\ Medium\ Nerd\ Font\ Complete\ Mono\ 12
syntax on
set background=dark
let g:onedark_termcolors=16
" colorscheme flattened_dark
@AndreiBarsan
Copy link

After a few of the vimtex updates, I had to use the following instead of let g:vimtex_compiler_callback_hooks = ... to avoid syntax errors:

        let g:vimtex_compiler_latexmk = {
          \ 'build_dir' : '',
          \ 'callback' : 1,
          \ 'continuous' : 1,
          \ 'executable' : 'latexmk',
          \ 'hooks' : [function('UpdateSkim')],
          \   'options' : [
          \       '-file-line-error',
          \       '-synctex=1',
          \       '-interaction=nonstopmode',
          \     ],
          \}

@kinium
Copy link

kinium commented Mar 13, 2023

It trows an error each time a tex file is opened:

VimTex: Deprecated options(s) detected! - g:vintex_quickfix_latexlog

How could I get rid off it?

@riddlework
Copy link

I was getting the same error, "VimTex: Deprecated options(s) detected! - g:vimtex_quickfix_latexlog". I just switched the line that had "g:vimtex_quickfix_latexlog" with "g:vimtex_quickfix_pplatex", which is another option given in the manual for the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment