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.

General setup

This setup works for me on linux. Install vim, okular, and synctex. Load vimtex plugin (see VimAwesome ↗ for details; note that the line with Plug changes depending on the vim plugin loader).

Plug 'https://github.com/lervag/vimtex'

Put the following into vim configuration (~/.vimrc).

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 <leader>lv (default \lv).

In Okular, go to Settings/Configure Okular/Editor switch to Custom Text Editor and set it to vim --remote-silent +%l %f and Ok. Now 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.