Editing LaTeX is way easier when one can click in code to jump in PDF, and vice-versa. This feature works out-of-the box in Overleaf or TeX Live, but using our own editor (like vim or vscode) needs some setup. I tried the setup of forward (code to PDF) and reverse search (PDF to code) with vim several times and failed. It is such a pain that I want to give this short tutorial on how I managed to make it work.
This setup works for me on linux.
Load vimtex plugin (see VimAwesome ↗ for details; note that the line with
Plug changes depending on the vim plugin loader).
Put the following into vim configuration (
let g:vimtex_view_general_viewer = 'okular' let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex' let g:tex_flavor = 'latex'
Reload configuration vim with
:source ~/.vimrc (or restart vim).
Open latex document and try
<leader>ll (by default
\ll) which should compile and show the latex file.
Forward search should already work on
In Okular, go to
Settings/Configure Okular/Editor switch to
Custom Text Editor and set it to
vim --remote-silent +%l %f and Ok.
Shift+Left click in Browse mode should give you reverse search.
It may be necessary to setup an alias for vim:
alias vim='vim --servername vim' so that the command that okular sends is received by a vim server.