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 can compile foo.tex with the following option:
$ pdflatex -synctex=1 foo.tex
Reverse Searching
First we need to 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}"
save and close the document.
Test your settings
- Create a file foo.tex and compile it using pdflatex.
- Open the new created foo.pdf document using zathura.
- While reading foo.pdf hold the control key and left-click the mouse.
- The source file should be opened in the very same line where you have 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
But this is to complicated... We can do forward search from within vim by edit vimrc file, run
and append the following:
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
endfunction
nmap :call SyncTexForward()
save and exit.
Test your settings
- Run:
- Move the cursor to a chosen line.
- Hold alt-s (that's alt and key character s at the same time).
- The file foo.pdf should be opened and forward to your chosen line.
Reverse search using vim (not gvim)
We can use vim to do reverse search by adding the following lines to our .bashrc file:
alias vimsn='vim-with-servername'
vim-with-servername() {
vim --servername 'vim' "$@"
}
alias vim=vimsn
and replacing gvim with vim in the $HOME/.config/zathura/zathurarc file.