I'm using vim to edit my tex files and I use latex suite as a plugin to compile my tex sources and view them in using Okular pdf viewer.

Setting the following in Okular settings makes inverse search work perfectly

gvim --servername GVIM --remote +%l %f

But having looked on the web and tried different ways to make forward search work within vim with latex suite, forward search is still working only partly for me in vim. I'm only able to do forward search with \ls in the main tex file. If I do \ls inside an include or input file then Okular would complain that it can't find the particular pdf for that include/input file which is true because only the main tex file has a pdf compiled.

I also tried a custom function which I found from an answer to a similar question here on TeXExchange: https://tex.stackexchange.com/a/2947/2031 but the path passed to Okular with this command is just a concatenation of the paths to both the main pdf and tex files.

Below are my current settings in my .vimrc related to this question:

let g:Tex_CompileRule_pdf = 'pdflatex -synctex=1 -src-specials -interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf = 'okular --unique'
function! SyncTexForward()
     let execstr = "silent !okular --unique %:p:r.pdf\#src:".line(".")."%:p &"
     exec execstr
nmap <Leader>f :call SyncTexForward()<CR>

1 Answer 1


I had exact the same problem. Modifying the function to pass the correct paths did the trick, at least for me. Here is the code:

function! SyncTexForward()
let s:syncfile = fnamemodify(fnameescape(Tex_GetMainFileName()), ":r").".pdf"
let execstr = "silent !okular --unique ".s:syncfile."\\#src:".line(".").expand("%\:p").' &'
exec execstr
nnoremap <Leader>f :call SyncTexForward()<CR>
  • Many thanks! That worked. Just one thing to note that in order for Tex_GetMainFileName() to work properly one should have a {main tex file name}.latexmain file in the same directory with their main tex file (as described here vim-latex.sourceforge.net/documentation/latex-suite/…)
    – ld_pvl
    Commented Nov 22, 2012 at 21:43
  • That's correct. Tex_GetMainFileName() is also used by other plugins. I have Latex-Box installed. The function is defined in the file findmain.vim. So you can copy the function in your own tex.vim and get rid of any plugins if you wish so.
    – panos
    Commented Nov 23, 2012 at 6:24
  • This worked for me. Just had to also set my viewer target to pdf (can choose from menus in gvim).
    – relG
    Commented Jul 3, 2018 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .