Skip to content

Instantly share code, notes, and snippets.

@vext01
Last active February 14, 2024 03:36
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vext01/16df5bd48019d451e078 to your computer and use it in GitHub Desktop.
Save vext01/16df5bd48019d451e078 to your computer and use it in GitHub Desktop.
Vim+Zathura+Synctex

Vim+Zathura+Synctex

  • In a script called 'vimura':
#!/bin/sh
echo $1
zathura -s -x "gvim --servername $1 -c \"let g:syncpdf='$1'\" --remote +%{line} %{input}" $*

For zathura >= 0.3.2 remove -s.

  • In your vimrc:
function! Synctex()
        " remove 'silent' for debugging
        execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . g:syncpdf
endfunction
map <C-enter> :call Synctex()<cr>
  • Build your latex doc with synctex enabled
pdflatex -synctex=1 ...
  • Open PDF with vimura script.

  • CTRL+Click in Zathura jumps to source in vim.

  • CTRL+Enter in vim jumps to corresponding position in PDF.

@mazunki
Copy link

mazunki commented Jul 1, 2022

I would love to hook in any motion to automatically call the function (which by some miracle doesn't reopen a new process, unless it's not open yet), but only if I already opened Zathura manually. Any ideas on how to do this? Having one function to only open Zathura (which I thought I had), and one to re-sync the position sounds like the ideal solution.

You can have it trigger on CursorMoveI events on *.tex file patterns.

autocmd CursorMoveI *.tex call OpenZathura()

With this whenever you enter insert and move around your cursor, zathura would do the same. But this also implies that you have to compile (if it's not compiled ) before entering insert mode.

I have another command to compile any *.tex file on BufReadPost and BufWritePost so i don't have to always remember about compiling it first. In my case it's not necessary to have zathura opened already. If the pdf file already exist , it (that function ) would open up without any problem

Nice! Didn't know about CursorMoveI, I'll add this myself when I get to it :)

@charlie39
Copy link

charlie39 commented Jul 2, 2022

@mazunki
This is my tex autocmd group

  augroup latex
    autocmd! CursorMovedI *.tex call OpenZathura()
    autocmd! BufWritePost,BufReadPre *.tex silent !compiler %
  augroup end

Also a tiny detail:

Also imp to have the compiler (whaterver compiling script or command you have) mapped to a certain key binding without silent, for for debugging.

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