how to use reverse and forward search with vim and zathura

Light weight and with vim like key-sequence zathura is a great choice for reading pdf files. To install it simply run

	# apt-get install zathura
We will use pdflatex and synctex on foo.tex source file. In the tex source file we can add the following line:

alternatively we an compile foo.tex with the following option:

$ pdflatex -synctex=1 foo.tex

Reverse Searching

First we edit zathurarc file, run

$ vim $HOME/.config/zathura/zathurarc
and append the following lines

# Adding reverse search between gvim and zathura
set synctex true
set synctex-editor-command "gvim --remote-silent +%{line} %{input}"
and than save and close the document. To test our definition we can compile foo.tex using pdflatex and open the new created foo.pdf document using zathura. From foo.pdf file we can go back to the source file by simply holding control and clicking the mouse. The source file will be opened in the very same line where we clicked.

Forward Searching

We can jump to line 511 column 1 in the file foo.pdf by using the command line, simply run:

$ zathura --synctex-forward 511:1:foo.tex foo.pdf
Nevertheless this is not what we want. What we really want is to find a way to do forward search from vim to zathura. To do this we edit vimrc file, run:

$ vim $HOME/.vimrc 
and append the following text:

function! SyncTexForward()
	let linenumber=line(".")
	let colnumber=col(".")
	let filename=bufname("%")
	let filenamePDF=filename[:-4]."pdf"
	let execstr="!zathura --synctex-forward " . linenumber . ":" . colnumber . ":" . filename . " " . filenamePDF . "&>/dev/null &"
	exec execstr 
nmap  :call SyncTexForward()
save and exit. Now reopen foo.tex with vim. Place the cursor in a desirable line and hold alt-s (that's alt and key character s at the same time). The file foo.pdf will be open (or simply go) and will point to where the cursor was placed in foo.tex file.