Saturday, December 29, 2007

PDFSync Inverse Searches in MacVim

Remember the post on doing inverse searches in Vim on OS X? The idea was to drop gvim-pdfsync into
(or somewhere else in your PATH) and then execute
gvim-pdfsync "%file" %line
to do inverse searches in Vim for OS X just like you can in Windows or in other UNIXes. For example, in Skim, under the PDFSync section of the Sync tab of the Preferences, you can put
Preset: Custom
Command: gvim-pdfsync
Arguments: "%file" %line

For MacVim

I thought it might be nice if I published how to do the same thing in the nascent MacVim, which supports servers just like Vim for Windows. Provided that you've installed the mvim shell script somewhere in your PATH, you can setup Skim with
Preset: Custom
Command: mvim
Arguments: --remote-tab-silent +":%line;foldo!" "%file"

or, if you don't like tabs
Preset: Custom
Command: mvim
Arguments: --remote-silent +":%line;foldo!" "%file"


Alternatively, if you really liked the gvim-pdfsync approach and want something similar for mvim, put mvimtab-pdfsync or (if you don't like tabs) mvim-pdfsync in your PATH (e.g., in /usr/local/bin) and then setup Skim for:
Preset: Custom
Command: mvimtab-pdfsync
Arguments: "%file" %line

or (if you used mvim-pdfsync)
Preset: Custom
Command: mvim-pdfsync
Arguments: "%file" %line
I hope that helps.


Daniele Avitabile said...

Hi Ted,

I am just about to install MacVim on Leopard. Inverse search is supported by Skim, as you wrote. Skim does not have a Leopard version yet, and I was wondering whether one could do the same with Preview, which in Leopard supports notes and Pdf merging. Do you know if this is possible?



Ted said...


I'm still running Tiger, and so I don't have experience with using the new version of Preview. I was under the impression that Leopard Preview did not support auto-reloading of PDFs, which is a deal breaker for me.

I would be surprised (SHOCKED, in fact) if Preview supported inverse searching. To support inverse searching, Preview would have to support PDFSync. If it supported PDFSync, I would imagine it would support PDF autoreloading.

So, my guess is that Preview does not (and probably will not) support inverse searching.

Sorry that I couldn't give you more help. You might try the Skim mailing list.


Joshtanga said...

I could not get this to work on MacOS 10.4. For example, this line command causes me problems.

mvim --remote-tab-silent 2 foo.tex

Ted said...

That's not the command line you want. If you want to test things at the command line, you'll want to do something like...

mvim --remote-tab-silent +":2;foldo!" "foo.tex"

Notice the plus sign. A command follows it. That command positions the cursor on line 2 and then opens any folds at that line.

DC from Foldio Portfolio said...

I am getting into the Macbook now (after using iPhone and iPad). I don't know anything about Mac OS but knwo alot about Windows. So I have this post very useful.

George said...

Hi, I'm having trouble getting this patch to work. When I apply the patch (in root), I get

patching file compiler.vim
Hunk #1 succeeded at 250 with fuzz 2 (offset 5 lines).
Hunk #2 succeeded at 272 (offset 7 lines).
Hunk #3 FAILED at 323.
1 out of 3 hunks FAILED -- saving rejects to file compiler.vim.rej

the first line of compiler.vim.rej begins with:

*** 317,368 ****
" will work.
function! Tex_ForwardSearchLaTeX()
if &ft != 'tex'
and the rest is too long to copy here

After this, I still can't do forward search, when I press \ls, I get "call Tex_ForwardSearchLatex()" but nothing happens. I'm using the latest version of vim-latex, but I've also tried an older version too.


Ted said...

George --

This particular post does not discuss a patch.

However, the most-recent revision of Vim-LaTeX within its source repository already includes the changes that I'm guessing you're referring to. That is, the patch at:

So if you download the latest verison of Vim-LaTeX, you'll already have all of these changes.

I don't have a Mac anymore, and so I can't verify that nothing has changed in Skim/MacVim that breaks things, but my guess is that everything still works as it used to.

You can find the latest version of Vim-LaTeX at:

at the top where it says "Looking for the latest version?"

Alternatively, see the two "Git" links on the bottom left of:

Adam said...

I'm still using this script instead of the mvim --remote approach; that approach does not seem to deal well with files already open.

In the applescript, you should use 'key code 53' instead of 'keystroke ESC'. On my machine, at least, keystroke ESC deletes a character.

Also, bufexists('$file') should be bufexists(bufname('$file')) if the file is open in a different buffer and the current file has a different path.

Ted said...

Adam -- thanks for the updates. I don't use a Mac anymore, and so I cannot test the changes you suggest (so I hesitate to make them immediately). However, hopefully someone reading the comments will catch them.