sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #1468: Backward search for latex documents on Mac os x

 tip karma   Rating 6/3, Viewed by 612 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   January 11, 2007 10:14      complexity:   intermediate
author:   Yonatan Amit      as of Vim:   5.7

Hi.

Latex is a great language for typesetting scientific documents.
The content of the document is written in some wonderful editor (vim) and compiled to a PDF with all the bells and whistles.
When editing a document, one often finds himself reading the PDF and then going back to the editor to change a couple of words.

A great feature found in some other editors is the ability to jump to the word under the cursor directly from the viewer,
this greatly reduces time spent while editing the document.
Luckily, there is a nice package called pdfsync that can be used to add this cool feature to vim.
pdfsync and a supporting viewer (I strongly recommend PDFView) can be configured to run a custom script when the user command-clicks inside the document.

Sadly, the current version of Vim for Mac doesn't support clientserver feature of the standard version, so I could not use the --remote
flag to send the command to vim.
So I hacked together a small UI script that tells the windowing environment to perform the remote actions.

Together. you can now point a word in the PDFView and it will take you to the right place in your editor of choice.

The script itself:
on run argv
  set CR to ASCII character of 13
  set ESC to ASCII character of 27
  set filename to (item 1 of argv)
  set lineNum to (item 2 of argv)
  tell application "Vim" to activate
  tell application "System Events"
    tell process "Vim"
    keystroke ESC & ":set hidden" & CR
    keystroke ":if bufexists('" & filename & "')" & CR
    keystroke ":    buffer " & filename  & CR
    keystroke ":else " & CR
    keystroke ":    edit " & filename & CR
    keystroke ":endif" & CR
    keystroke ":" & lineNum & CR
    keystroke "zO" -- open folds, if any exists.
    end tell
  end tell
end run

 rate this tip  Life Changing Helpful Unfulfilling 

<< Notes to accompany : "Introduction to display Editing using vi" paper. | Ctrl-N completion for XML/XSLT attributes >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo