LaTeX-Box-Team / LaTeX-Box

Lightweight Toolbox for LaTeX - New Official repository
http://www.vim.org/scripts/script.php?script_id=3109
GNU General Public License v3.0
395 stars 66 forks source link

Suggested SumatraPDF inverse search command doesn't quite work on Windows. #251

Closed dmsul closed 5 years ago

dmsul commented 9 years ago

I was having some trouble using the suggested inverse search command from the docs, where the focus would shift back to Sumatra. The command is (from line 783 of the help doc, under "FAQ"):

let g:LatexBox_viewer = 'SumatraPDF -reuse-instance -inverse-search '
  \ . '"gvim --servername ' . v:servername
  \ . ' --remote-send \"^<C-\^>^<C-n^>'
  \ . ':drop \%f^<CR^>:\%l^<CR^>:normal\! zzzv^<CR^>'
  \ . ':call remote_foreground('''.v:servername.''')^<CR^>\""'

However, from Vim's remote.txt help doc, line 125:

Win32 Note: Making the Vim server go to the foreground doesn't always work, because MS-Windows doesn't allow it. The client will move the server to the foreground when using the --remote or --remote-wait argument and the server name starts with "g".

I haven't really used the command server stuff before, but as far as I can tell, the following code is almost functionally equivalent to the above, but will shift the window focus to Vim:

let g:LatexBox_viewer = 'SumatraPDF -reuse-instance -inverse-search '
  \ . '"gvim --servername ' . v:servername
  \ . ' --remote-silent '
  \ . '\"+\%l|normal zv|'
  \ . 'call remote_foreground('''.v:servername.''')\"'
  \ . ' \"\%f\""'

I tried to add a normal zz to that chain of Ex commands but it always threw errors. I figure getting the focus to shift consistently is more important than centering the line. I also don't know how to deal with the "if the server name starts with 'g'" nonsense, but the default server names (GVIM, GVIM1, etc.) work just fine.

I will test this later when I have access to a Linux machine, and will submit a PR if it is warranted. But I'm very much a Linux beginner and wanted to check that the shift from --remote-send to --remote-silent will not break things for the wider (more Linux-y) community.

(Also, many thanks for the plugin. I'm still transitioning from Latex-Suite but I'm really enjoying it so far.)