TLDR;


10 months ago I setup my vim to support jump to and from PDF viewer. Since then I jumped into NeoVim which broke this setup, so here is the new one.

In NeoVim ~/.config/nvim/init.lua apart from the typical lazy setup ↗ we include lervag/vimtex as a plugin while disabling lazy loading. It is mentioned in the VimTex README ↗ lazy loading messes the VimtexInverseSearch command; I tried, it really does.

require('lazy').setup({
    {                               -- LaTeX support
        'lervag/vimtex',
        lazy = false,
    },
})

Next, setup vimtex:

vim.g.vimtex_view_general_viewer = 'okular'
vim.g.vimtex_view_general_options = '--unique file:@pdf\\#src:@line@tex'
vim.g.tex_flavor = 'latex'
vim.g.vimtex_compiler_progname = 'nvr'

Now, opening a .tex file and <leader>ll should compile it and open PDF in Okular.

To support Inverse search (clicking PDF to move editor) we install neovim-remote (requires python3 and pip3) which adds a new command nvr.

  • pip3 install neovim-remote

Next, go to Okular and navigate menu to Settings/Configure Okular/Editor/Custom Text Editor" which should be set to nvr --remote-silent +%l %f.

Note that the PDF must be compiled through the NeoVim, otherwise it may not contain hints on where it should jump. VimTex does not compile the document if source did not change so you may have to do a meaningless change to get the hints in.

Now in Okular’s Browse Mode holding Shift and Left Cicking should move your NeoVim.