I managed to let forward search work on my Windows machine with the following specification in my _vimrc:

let g:Tex_ViewRule_pdf = 'C:\Program Files\SumatraPDF\SumatraPDF.exe -reuse-instance -inverse-search "\"C:\vim\vim74\gvim\" -c \":RemoteOpen +\%l \%f\"" ' The environment: I am running a Gvim installation on a Windows machine, with latest SumatraPDF (removing the Tab feature) and have applied this patch that aimed at fixing the forward search problem.

However, it only works in a very restrictive way: When I want to use the <leader>ls mapping to trigger a forward jump, I would encounter a 10 seconds delay if I have any SumatraPDF window opened.

Only when there is no SumatraPDF.exe running, may I get a instant forward jump.

Any help that may help me out of this akward situation is well applaused!

Thank you!

Posts that relates to the forward search problem:

Vim-Latex: forward search doesn't work


Although i can see this is quite old, I've been dealing with this issue for a couple of hours and just got around it. I too have gvim on windows with the vim-latex plugin having trouble with forward search.

The main issue seems to be that the set shellslash isn't playing well with the forward search call to sumatra. I know this setting (shellslash) is recommended for vim-latex on windows but comment it out for forward search to work correctly.

some important vimrc lines:

        "set shellslash
        let g:Tex_DefaultTargetFormat ='pdf'
        let g:Tex_ViewRule_pdf ='SumatraPDF'
        let g:Tex_CompileRule_pdf='pdflatex -synctex=1 - 
        interaction=nonstopmode -file-line-error-style $*'

Other notes:

  1. make sure to add the sumatrapdf.exe folder to your PATH variable, there's a line in the compiler.vim file:

    elseif (viewer =~? "^sumatrapdf")

which seemed to break for me when i included a path in the Tex_ViewRule_pdf variable.

  1. the "set shellslash" line doesn't actually remove shellslash if you have it enabled elsewhere in the file, i just included it as a reminder to comment that part out.

It has been a long time since the last time that I have updated my Gvim + Sumatra settings. I will post the complete set of settings that I consider as relevant.

In my view, specifying the full path along with the viewing options is not too bad: the side-effect of doing so is that --- the corresponding settings for backward-search is updated automatically.

  • The specific setting for the g:Tex_ViewRule_pdf variable.

let g:Tex_ViewRule_pdf = 'C:\Program Files\SumatraPDF\SumatraPDF.exe -reuse-instance -inverse-search "\"C:\vim\vim80\gvim.exe\" -c \":RemoteOpen +\%l \%f\"" '

  • The full set of settings that I am using for Sumatra + Gvim on a Windows machine.

" Vim-Latex {{{ filetype plugin on filetype indent on set shellslash set grepprg=grep\ -nH\ $* set diffexpr=MyDiff() function! MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ '\<cmd' let cmd = '""' . $VIMRUNTIME . '\diff"' let eq = '"' else let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"' endif else let cmd = $VIMRUNTIME . '\diff' endif silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq endfunction let g:tex_flavor='atex' let g:Tex_GotoError=0 " Will keep the cursor as is. "let g:Tex_IgnoredWarnings = " \'Underfull'."\n". " \'Overfull'."\n". " \'specifier changed to'."\n". " \'You have requested'."\n". " \'Missing number, treated as zero.'."\n". " \'There were undefined references'."\n". " \'Citation %.%# undefined'."\n". " \'Font Warning' let g:Tex_DefaultTargetFormat='pdf' let g:Tex_CompileRule_pdf = 'pdflatex --synctex=-1 -src-specials -interaction=nonstopmode $*' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Pair of settings that handle LaTeX Preview Color settings let g:Tex_ViewRule_pdf = 'C:\Program Files\SumatraPDF\SumatraPDF.exe -reuse-instance -inverse-search "\"C:\vim\vim80\gvim.exe\" -c \":RemoteOpen +\%l \%f\"" ' " let g:Tex_ViewRule_pdf = 'C:\Program Files\SumatraPDF\SumatraPDF.exe -invert-colors -reuse-instance -inverse-search "\"C:\vim\vim80\gvim.exe\" -c \":RemoteOpen +\%l \%f\"" ' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " The following section is no longer relevant, as we no longer use Vim to build " the LaTeX files. let g:Tex_MultipleCompileFormats='pdf' " Skip these Tex compilation errors. let g:Tex_IgnoredWarnings = \'Underfull'."\n". \'Overfull'."\n". \'specifier changed to'."\n". \'You have requested'."\n". \'Missing number, treated as zero.'."\n". \'There were undefined references'."\n". \'Citation %.%# undefined'."\n". \'Float too large'."\n". \'Package natbib Warning: Empty'."\n". \'LaTeX Font Warning' let g:Tex_IgnoreLevel = 10 " }}}


The g:Tex_ViewRule_pdf variable should only contains the name of the viewer executable. Otherwise, if you set the variable with the full path to the executable, you have to modify the script file: ftplugin/vim-latex/ftplugin.vim +381, in which the content of the variable is expected to be started with the string: "sumatrapdf". You can simply remove the ^ from elseif (viewer =~? "^sumatrapdf") at line 381 to fulfill that.

  • Thank you for your clarification. I will post my working version that runs well on more than 10 Windows machines in a separate post. – llinfeng Apr 20 '18 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.