Instantly share code, notes, and snippets.

@vext01 /vimura.md
Last active Oct 16, 2018

Embed
What would you like to do?
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.

@natema

This comment has been minimized.

Show comment
Hide comment
@natema

natema Sep 17, 2016

Thank you so much, I tried to make synctex work with evince but eventually gave up. Now I can finally fully enjoy the power of vim without any regret. Only one question: is there any way to make this work by starting gvim first and then opening zathura with \ll?

natema commented Sep 17, 2016

Thank you so much, I tried to make synctex work with evince but eventually gave up. Now I can finally fully enjoy the power of vim without any regret. Only one question: is there any way to make this work by starting gvim first and then opening zathura with \ll?

@scemama

This comment has been minimized.

Show comment
Hide comment
@scemama

scemama Feb 10, 2017

Thanks! Very useful!

scemama commented Feb 10, 2017

Thanks! Very useful!

@fmeynadier

This comment has been minimized.

Show comment
Hide comment
@fmeynadier

fmeynadier Sep 5, 2017

To make it work without starting a new vim instance, allowing to link to an already open file, I think you just have to use a fixed servername, i.e.

vimura:

#!/bin/sh
echo $1
zathura -s -x "vim --servername vim -c \"let g:syncpdf='$1'\" --remote +%{line} %{input}" $*

and put this alias in .bashrc (or equivalent)
alias vim='/usr/bin/vim --servername vim'
At least it works for my basic usage of vim, I don’t know if there are side effects with gvim and/or more advanced usage of vim.

You could also keep the "vimura" script as it is and launch vim with the corresponding servername (i.e. the .tex filename).

fmeynadier commented Sep 5, 2017

To make it work without starting a new vim instance, allowing to link to an already open file, I think you just have to use a fixed servername, i.e.

vimura:

#!/bin/sh
echo $1
zathura -s -x "vim --servername vim -c \"let g:syncpdf='$1'\" --remote +%{line} %{input}" $*

and put this alias in .bashrc (or equivalent)
alias vim='/usr/bin/vim --servername vim'
At least it works for my basic usage of vim, I don’t know if there are side effects with gvim and/or more advanced usage of vim.

You could also keep the "vimura" script as it is and launch vim with the corresponding servername (i.e. the .tex filename).

@fmeynadier

This comment has been minimized.

Show comment
Hide comment
@fmeynadier

fmeynadier Sep 6, 2017

Also, if you prefer not to use the g:syncpdf variable defined in the vimura script, leaving you free to display it independently and still get forward search :

function! Synctex()
  " remove 'silent' for debugging
  execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . bufname('%')[:-5]. ".pdf"
  redraw!
endfunction
map <C-enter> :call Synctex()<cr>

This assumes of course corresponding root names between the tex file and the pdf file.
Also, with vim I have to redraw terminal after that, hence the "redraw!" that might not be needed with gvim.

I realize this may be going away from the initial intent, and may be less robust, but I thought it could be useful to others...

fmeynadier commented Sep 6, 2017

Also, if you prefer not to use the g:syncpdf variable defined in the vimura script, leaving you free to display it independently and still get forward search :

function! Synctex()
  " remove 'silent' for debugging
  execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . bufname('%')[:-5]. ".pdf"
  redraw!
endfunction
map <C-enter> :call Synctex()<cr>

This assumes of course corresponding root names between the tex file and the pdf file.
Also, with vim I have to redraw terminal after that, hence the "redraw!" that might not be needed with gvim.

I realize this may be going away from the initial intent, and may be less robust, but I thought it could be useful to others...

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