It would help to know which, if any, LaTeX plugin you're using for vim. (E.g., the latex-suite, vim-auctex, latex-box, etc.)
Next, as far as viewer choice, the only widely used open source PDF viewer for Linux which currently supports SyncTeX well out of the box is Okular. That's probably your best choice.
There are instructions fo setting up SyncTeX with Okular with the vim-latex plugin here, and some related observations here. I had mixed results following those directions. Here's what seems to be important.
Be sure that your LaTeX compilation method (which will depend on your plugin) calls pdflatex (or xelatex or whatever) with the -synctex=1
flag.
I think something like this should suffice for Forward Searches with Okular, though it might be better to try to rewrite or modify the forward search function for your plugin (there's some info on that in one of the links above). Put this in your .vimrc (and change the mapping to whatever you like).
function! SyncTexForward()
let execstr = "silent !okular --unique %:p:r.pdf\\#src:".line(".")."%:p &"
exec execstr
endfunction
nmap <Leader>f :call SyncTexForward()<CR>
For reverse searches, set the editor line in Okular to gvim --servername GVIM --remote +%l %f
. It might also work to use gvim --servername GVIM --remote-send "<Esc>%lgg"
if you only use it with the file already open. Change the servername to whatever you use. (Not sure if it's different with regular vim, but this doesn't make much sense out of a graphical environment.)
I do not have Okular installed right now, however, so I could not test any of that. (And the links I gave earlier have slightly different advice which is worth trying.) I really hope someone with both Okular and gvim installed can test this advice, and correct where I went wrong.
And all of that advice isn't going to work well if you're using subdocuments called through \input{...}
or \include{...}
, where the PDF name doesn't match the name of the document you're editing. There are ways around that, but it would require knowing more about what LaTeX plugins and methods you're already using, if any.
However, other choices are kinda/sorta already available. The next version of evince will support SyncTeX through D-Bus, and apparently someone is already working on a plugin for vim to make use of it. Details here. However, it's very unlikely that this version of evince is already available for your Linux distribution, and there may be some problems with it.
There's an old fork of an old version evince that provides synctex support; there are instructions that come with that detail how to set this up with gvim. It works fine. It's easy to set up if you're using Arch Linux, since this is in the AUR. If you're not, I don't know how hard it would be to compile. (I used to use Ubuntu before Arch, and couldn't get it working there, but that may have been my ignorance.)
Next, I wrote some scripts that provide very limited, very poor, but still better than nothing, synctex support between gvim and the open-source vim-like PDF viewer Zathura, which uses vim-like keybindings. You'll find them mentioned and detailed in this thread in the Arch forums here. (post #370)
Finally, I think this kind of stuff will work its way into the major LaTeX plugins for vim soon, and then you don't have to resort to so much trial and error.
If you are using file names with blanks, the problem is with TeXstudio and TeXmaker, whose command line is something like (supposing your file is C cè.tex)
pdflatex.exe -synctex=1 -interaction=nonstopmode C cè.tex
while the corresponding command line in WinEdt is
pdflatex.exe -synctex=-1 -interaction=errorstopmode "C cè.tex"
so you would have to change TeXstudio command line (in Options -> Configure -> commands) to
pdflatex.exe -synctex=1 -interaction=nonstopmode "%.tex"
Best Answer
I use WinEdt, and here is what works for me:
"C:\Program Files\WinEdt Team\WinEdt 10\WinEdt.exe" "[Open(|%f|);SelPar(%l,10);]"
In Sumatra click Menu/Settings/Options, then in the last box on that dialog box copy and paste the above.