One of my projects this winter break has been to finally take the leap and switch to vim for all my text editing needs. The full story behind this momentous decision will have to wait for another day, but the short version is simply that, as my typing has improved over the past couple of months, I’ve finally started to notice how much reaching for the mouse slows me down. My goal in learning vim is to spend as much time as possible with my fingers on the home row. The learning curve has been steep indeed, but I’m finally at the point where I’m more productive in vim than I used to be in Sublime Text. As of earlier today, however, one problem remained: I didn’t have a good setup for LaTeX and vim. Back in 2013 I learned about the fantastic LaTeXTools plugin for Sublime which I’ve been using ever since. My main precondition for switching to vim has been to find a setup with comparable functionality.
- I couldn’t figure out how to set things up so that Vim-LaTeX would use
latexmkto compile a pdf by running
pdflatexthe appropriate number of times (as is done by default in LaTeXTools) and,
- I couldn’t get forward or reverse search working with SyncTeX.
After a whole day of Googling and tinkering, I’m 95% satisfied with my solution, so here it is. You can view and fork all of the relevant configuration files in my dotfiles repository on GitHub. I keep a copy of the scripts from Step 2 in my bin repository.
Part I: Compilation Commands
First, make sure that you have all of the lines that a required for using vim-latex in your
I also include the following optional, but sensible, suggestions:
Now add these lines to your here’s the important part - add the following to your
After restarting vim and using
\ll to compile your
.tex file, you should have a pdf file generated by
latexmk along with various auxiliary files including a synctex file.
We’ll need this in the second step.
Part II: Evince and SyncTeX
I knew that forward and reverse search were possible using the (default) evince pdf viewer on Ubuntu 14.04 because both worked perfectly on my system with LaTeXTools and Sublime.
evince directory in the GitHub Repo for LaTeXTools, I found three files that seemed to match those linked to on this thread on the Ubuntu forums.
After downloading both sets of file, I diffed each pair.
By doing this I learned that the
evince_forward_search python scripts from LaTeX tools are slightly altered versions of the files from the Ubuntu forum that incorporate some of the more helpful suggestions from later in the thread.
evince_sync file, on the other hand, is a modified version of the
evince script from the Ubuntu forum that has been changed to call Sublime rather than gvim for reverse search and to source both python scripts without assuming that they have been set to be executable.
Since I knew they already worked on my system, I decided to use the
evince_backward_search scripts from LaTeXTools and combine them with the
evince script from the Ubuntu forum.
Here are the steps I followed:
- Copy the
evincefile from the Ubuntu forum thread and the
~/bin. If you’re on Ubuntu, you may need to create
~/binfirst. If you find yourself in this situation, restart your machine before proceeding and
~/binwill automatically be added to your search path.
- Make each of the three scripts executable with
chmod +x [filename]
- Add the following lines to
~/.vim/after/ftplugin/tex.vim(if this file doesn’t exist on your machine, create it first)
And you’re done!
Well, almost everything works.
\ls does a forward search and control-click inside of evince does a reverse search.
The weird thing is that the first time I do a reverse search within a given pdf, evince launches two duplicate copies of gvim.
All subsequent reverse searches work exactly as expected.
I have absolutely no idea why this is, so if you have any thoughts, send me a tweet or email.
In the meantime, my new LaTeX setup is good enough for me to get down to work!