Vim Tips Wiki
(Change to TipImported template + severe manual clean)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1468
 
|id=1468
 
|previous=1465
 
|previous=1465
 
|next=1469
 
|next=1469
|created=January 11, 2007
+
|created=2007
 
|complexity=intermediate
 
|complexity=intermediate
|author=Yonatan Amit
+
|author=
|version=5.7
+
|version=
|rating=6/3
+
|rating=
  +
|category1=LaTeX
  +
|category2=
 
}}
 
}}
  +
When editing LaTeX with Vim and previewing the pdf with a pdf viewer, you would like to be able to click on a word in the pdf viewer and have vim automatically jump to the location in the source file you clicked on. This is called backwards search, since clicking in the pdf viewer updates the vim location. To update the pdf viewer to a page containing the current location in Vim, see [[Open pdf to the current location in a LaTeX file]].
Latex is a great language for typesetting scientific documents.
 
   
  +
==Linux==
The content of the document is written in some wonderful editor (Vim) and compiled to a PDF with all the bells and whistles.
 
  +
{{Todo}}
  +
There are some instructions [http://jlebl.wordpress.com/2011/01/13/vim-evince-and-forward-and-backward-latex-synctex-search/ here], but they should be copied into this page.
   
  +
==Windows==
When editing a document, one often reads the PDF, then goes back to the editor to change a couple of words.
 
  +
{{Todo}}
  +
Find how to do this on Windows.
   
  +
==Mac==
A great feature found in some other editors is the ability to jump to the word under the cursor directly from the viewer. That greatly reduces time spent while editing the document.
 
 
Mac OS has a package called 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.
   
  +
To enable backwards search, install and configure the {{script|id=1951|text=gvim-pdfsync}} plugin.
Luckily, there is a nice package called pdfsync that can be used to add this cool feature to Vim.
 
   
  +
==Plugins==
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.
 
  +
*[http://atp-vim.sf.net Automatic LaTeX plugin] has forward and backward search which works for quite a few viewers: xpdf (v3.03), evince, okular, xdvi, open (on MacOs). Unfortunatelly, the plugin doesn't officially support Windows.
 
  +
*[http://vim-latex.sf.net LaTeX Suite] also support forward and reverse searching.
Sadly, the current version of Vim for Mac doesn't support clientserver feature of the standard version, so I could not use the <tt>--remote</tt> 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 to a word in the PDFView and it will take you to the right place in your editor of choice.
 
 
The AppleScript itself:
 
 
<pre>
 
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 &amp; ":set hidden" &amp; CR
 
keystroke ":if bufexists('" &amp; filename &amp; "')" &amp; CR
 
keystroke ": buffer " &amp; filename &amp; CR
 
keystroke ":else " &amp; CR
 
keystroke ": edit " &amp; filename &amp; CR
 
keystroke ":endif" &amp; CR
 
keystroke ":" &amp; lineNum &amp; CR
 
keystroke "zO" -- open folds, if any exists.
 
end tell
 
end tell
 
end run
 
</pre>
 
 
==Comments==
 
I have just uploaded a {{script|id=1951|text=bash script}} that updates this AppleScript.
 
 
The improvements:
 
* It's a bash script, and so it's easier to use in PDFSync-compatible applications like [http://skim-app.sourceforge.net/ Skim].
 
* It has no problems when you try to open two different files with the same base name.
 
* It has no problems with filenames with spaces.
 
 
TedPavlic July 2007
 
 
----
 
[[Category:Mac OS X]]
 
[[Category:LaTeX]]
 

Latest revision as of 17:03, 23 September 2012

Tip 1468 Printable Monobook Previous Next

created 2007 · complexity intermediate · version 


When editing LaTeX with Vim and previewing the pdf with a pdf viewer, you would like to be able to click on a word in the pdf viewer and have vim automatically jump to the location in the source file you clicked on. This is called backwards search, since clicking in the pdf viewer updates the vim location. To update the pdf viewer to a page containing the current location in Vim, see Open pdf to the current location in a LaTeX file.

Linux[]

 TO DO 
There are some instructions here, but they should be copied into this page.

Windows[]

 TO DO 
Find how to do this on Windows.

Mac[]

Mac OS has a package called 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.

To enable backwards search, install and configure the gvim-pdfsync plugin.

Plugins[]

  • Automatic LaTeX plugin has forward and backward search which works for quite a few viewers: xpdf (v3.03), evince, okular, xdvi, open (on MacOs). Unfortunatelly, the plugin doesn't officially support Windows.
  • LaTeX Suite also support forward and reverse searching.