Vim Tips Wiki
No edit summary
m (fixing dead links)
 
(26 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{review}}
 
{{duplicate|361}}
 
 
{{TipImported
 
{{TipImported
 
|id=225
 
|id=225
 
|previous=224
 
|previous=224
|next=226
+
|next=227
|created=March 20, 2002
+
|created=2002
 
|complexity=basic
 
|complexity=basic
 
|author=Dimitri Antoniou
 
|author=Dimitri Antoniou
|version=6.0
+
|version=6.0+
 
|rating=125/43
 
|rating=125/43
 
|category1=
 
|category1=
 
|category2=
 
|category2=
 
}}
 
}}
Vim can interact with the tricks that the latest xdvi does:
+
Vim can interact with the tricks that the latest xdvi or kdvi does:
* If one clicks at some place in xdvi, Vim automatically jumps to the corresponding line in the LaTeX source file ("reverse search")
+
*If one clicks at some place in xdvi (usually Ctrl+Button1), Vim automatically jumps to the corresponding line in the LaTeX source file ("reverse search")
* Also, from inside Vim, one can jump to the corresponding line in xdvi which becomes highlighted ("forward search").
+
*Also, from inside Vim, one can jump to the corresponding line in xdvi which becomes highlighted ("forward search").
   
First of all, the latex document need to tell the latex compiler to set marks in the dvi file. Only put :
+
First of all, the latex document need to tell the latex compiler to set marks in the dvi file. Only put:
 
<pre>
 
<pre>
 
\usepackage{srcltx}
 
\usepackage{srcltx}
 
</pre>
 
</pre>
In the preambule of your latex document or compile with :
+
in the preamble of your latex document, or compile with:
 
<pre>
 
<pre>
latex --src [your_file.tex]
+
latex --src [your_file.tex]
 
</pre>
 
</pre>
   
It works perfectly well with vim or gvim on one side and xdvi on the other side, even with multiple couple (vim,xdvi).
+
It works perfectly well with Vim or gvim on one side and xdvi on the other side, even with multiple couple (vim, xdvi). It works also fine with kdvi but can be a little less "smooth".
It works also fine with kdvi but can be a little less "smooth".
 
   
 
==With xdvi==
 
==With xdvi==
 
It's very simple. In your <code>.vimrc</code> file, add at the end:
 
It's very simple in your ".vimrc" file add at the end :
 
 
<pre>
 
<pre>
:map \ld :execute '!xdvi -editor "vim --servername 'v:servername' --remote +\%l \%f" -sourceposition ' . line(".") . expand("%") . " " . expand(Tex_GetMainFileName(':r')) . ".dvi &" <CR><CR>
+
:map \ld :execute '!xdvi -editor "vim --servername 'v:servername' --remote +\%l \%f" -sourceposition ' . line(".") . expand("%") . " '" . expand(Tex_GetMainFileName(':r')) . ".dvi' >/dev/null&" <CR><CR>
 
</pre>
 
</pre>
  +
and
 
  +
and in your <code>.bashrc</code>:
 
<pre>
 
<pre>
 
alias vim='vim --servername vimtex'
 
alias vim='vim --servername vimtex'
<pre>
+
</pre>
  +
  +
The first allows the forward search by <code>\ld</code> in normal mode.
  +
 
To allow the reverse search, Vim has to be opened with <code>vimtex</code> servername; that's the reason for the second line. (I don't use the normal shortcut <code>\ls</code> as that doesn't allow me to use the <code>v:servername</code> variable, see end of this tip.)
   
 
Keep in mind that any other program that communicates with Vim server should be aware of the name change (for example <code>jabref</code>). A little script like [http://web.archive.org/web/20090715013750/http://corentin.barbu.free.fr/codes/stable/ouvre ouvre] can avoid to systematically name the Vim server "vimtex".
The first allow the forward search by "\ld" in normal mode, to allow the reverse search, vim has to be opened with vimtex servername, that's the reason of the second line. (I don't use the normal shortcut "\ls" for it doesn't allowed me to use the "v:servername" variable, see end of this tip)
 
   
  +
Note: On my system (Ubuntu 8-10, with the latex-suite installed via vim-addon-manager) this works, but only if I substitute 'gvim' for 'vim'. Also, for things to work I must, in order, 1) Open my tex file with gvim, 2) Open my dvi file with the command \ld 3) reverse-search using Ctrl + left-mouse-click.
Keep in mind that other program that communicate with vim server should be aware of the name change (for example jabref). A little script like [http://corentin.barbu.free.fr/code/stable/ouvre ouvre] can avoid to sistematically name the vim server "vimtex".
 
   
==With kdvi==
+
==With kdvi==
If you run it on gnu/linux, I've maid a little script that make the work for you (for use with vim) : [http://corentin.barbu.free.fr/code/stable/install_fsearch_kdvi.sh install_fsearch_kdvi.sh] but this doesn't allow to run multiple couple of (vim kdvi)
+
If you run it on gnu/linux, I've made a little script to do the work for you (for use with Vim): [http://corentin.barbu.free.fr/codes/stable/install_fsearch_kdvi.sh install_fsearch_kdvi.sh] but this doesn't allow running multiple couples of (vim, kdvi). The tips for xdvi would apply, but I've no more time to set it.
the same tips than ahead for xdvi would apply but I've no more time to set it.
 
   
Then in kdvi in "configuration> configure kdvi > dvi specificity" set Editor to "vim"
+
Then in kdvi in "<code>configuration> configure kdvi > dvi specificity</code>" set Editor to "<code>vim</code>".
   
You can then make forward search in vim or gvim by "\lf" in normal mode.
+
You can then forward search in Vim or gvim by <code>\lf</code> in normal mode.
   
If you want to use it from gvim only change :
+
If you want to use it from gvim only, in the script change:
 
<pre>
 
<pre>
 
echo "alias vim='vim --servername KDVI'" >> ~/.bashrc
 
echo "alias vim='vim --servername KDVI'" >> ~/.bashrc
Line 61: Line 61:
 
</pre>
 
</pre>
   
It works with a little script in your ~/bin/ directory. Please review it in case it doesn't work.
+
It works by a little script in your <code>~/bin/</code> directory.
   
Here is the source code of the install script :
+
Here is the install script:
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
 
script_name=~/bin/fsearch_kdvi.sh
 
script_name=~/bin/fsearch_kdvi.sh
if [[ ! -e ~/bin ]] ; then
+
if [[ ! -e ~/bin ]] ; then
 
mkdir ~/bin/
 
mkdir ~/bin/
 
fi
 
fi
Line 91: Line 91:
   
 
==Windows tip==
 
==Windows tip==
If you use the MikTeX distribution on Win32, you can play the same game with Vim and yap. I use the following with Vim 6.0 and (old) MikTeX 1.20b .
+
If you use the MikTeX distribution on Win32, you can play the same game with Vim and yap. I use the following with Vim 6.0 and (old) MikTeX 1.20b.
   
 
From my Vim script for tex files:
 
From my Vim script for tex files:
  +
<pre>
 
execute '!start yap -1 -s' line(".") . expand("%:t") expand("%:p:r")
  +
</pre>
   
 
(Of course, I have a <code>:map</code> and <code>:menu</code> to do this.) This expands to something like:
execute '!start yap -1 -s' line(".") . expand("%:t") expand("%:p:r")
 
  +
<pre>
 
!start yap -1 -s 1353foo.tex c:\path\to\foo
  +
</pre>
   
 
In yap, from the View/Options panel, choose the "Inverse Search" tab and enter:
(Of course, I have a :map and :menu to do this.) This expands to something like
 
  +
<pre>
 
 
gvim --remote +%l %f
!start yap -1 -s 1353foo.tex c:\path\to\foo
 
  +
</pre>
 
 
in the "Command line" box. This can probably be improved: doesn't the installer put a <code>.bat</code> file somewhere?
In yap, from the View/Options panel, choose the "Inverse Search" tab and enter
 
 
gvim --remote +%l %f
 
 
in the "Command line" box. This can probably be improved: doesn't the installer put a .bat file somewhere? ...
 
   
 
----
 
----
 
The following mapping may also be useful (in one line):
 
The following mapping may also be useful (in one line):
  +
<pre>
 
map _g :exe 'silent !xdvi -editor "vim --servername ' . v:servername . ' --remote +\%l \%f" -sourceposition ' . line (".") . expand("%") . " " . expand("%:r") . ".dvi &" \| redraw!<CR>
  +
</pre>
   
 
It starts up an xdvi (if necessary) and does a forward search. Reverse search will jump to the location in the same Vim.
map _g :exe 'silent !xdvi -editor "vim --servername ' . v:servername . ' --remote +\%l \%f" -sourceposition ' . line (".") . expand("%") . " " . expand("%:r") . ".dvi &" \| redraw!<CR>
 
 
It starts up an xdvi (if necessary) and does forward search.
 
Reverse search will jump to the location in the same Vim.
 
   
 
----
 
----
as a followup to benji's excellent tip for yap, (win32)
+
As a followup to benji's excellent tip for yap, (win32)
the command :!start as opposed to :! does a kind of fork, so Vim won't wait for the executed program to finish
+
the command <code>:!start</code> as opposed to <code>:!</code> does a kind of fork, so Vim won't wait for the executed program to finish.
   
i.e. type:
+
That is, type:
  +
<pre>
exe 'silent !start yap -1 -s' line(".") . expand("%:t") expand("%:r") .'.dvi'
+
exe 'silent !start yap -1 -s' line(".") . expand("%:t") expand("%:r") .'.dvi'
  +
</pre>
   
 
so you don't have to close yap before Vim becomes responsive again. See {{help|:!start}}.
 
so you don't have to close yap before Vim becomes responsive again. See {{help|:!start}}.
   
 
----
 
----
I do make use of the above a lot---and it usually works great. However, to handle spaces in the file path, it needs a little modification:
+
I make use of the above a lot, and it usually works great. However, to handle spaces in the file path, it needs a little modification:
  +
<pre>
 
exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'
  +
</pre>
   
 
The corresponding mapping (to <code>_g</code>) is:
exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'
 
  +
<pre>
 
 
map _g :exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'<CR><CR>
The corresponding mapping (to _g) is:
 
  +
</pre>
 
map _g :exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'<CR><CR>
 
   
 
----
 
----
 
I am using the following in my ~/.Xdefaults:
 
I am using the following in my ~/.Xdefaults:
  +
<pre>
 
xdvi.editor: gvim --servername %f --remote-silent +%l %f
+
xdvi.editor: gvim --servername %f --remote-silent +%l %f
  +
</pre>
   
 
With the advantage that I can have multiple Xdvi instances with different files and they all know, what Vim they have to address to.
 
With the advantage that I can have multiple Xdvi instances with different files and they all know, what Vim they have to address to.
   
Also, you may have multiple Xdvi instances with the _same_ file and they will all interact with the same Vim.
+
Also, you may have multiple Xdvi instances with the same file and they will all interact with the same Vim.
   
 
----
 
----
There's not clientserver support on vanilla vim [to be verified as it works well know with vim].
+
There's not clientserver support on vanilla Vim [to be verified as it works well now with Vim].
 
   
 
----
 
----
Line 150: Line 156:
 
==Problem solving==
 
==Problem solving==
 
This part has been partly reviewed, other contributors welcome.
 
This part has been partly reviewed, other contributors welcome.
It's only works for quite recent xdvi versions (>= 22.38), (or recent Unix/Linux versions), xdvi can interact with any editor provided with a client-server mode.
 
Vim as to be compiled with the client-server option, on Ubuntu 8.04 it's ok, for gvim it's usually the case. On Linux Mandrake 9.0. gvim is compiled with the client-server option and vim is not.
 
   
 
0-Check the configuration of the source file (file.tex)
0-Check that your xdvi version provides the "source-special" functions, by typing 'xdvi -version' or 'man xdvi'
 
  +
 
Check you've got the package <code>srcltx.sty</code> and <code>\usepackage{srcltx}</code> (which should be commented out when one finishes and is ready for printing etc).
  +
 
If you do not have the LaTeX package <code>srctex</code>, try compiling your file with:
  +
<pre>
 
latex --src [your_file.tex]
  +
</pre>
  +
 
which works for me.
  +
  +
===xdvi===
 
Forward and reverse search only works for quite recent xdvi versions (>= 22.38), (or recent Unix/Linux versions), xdvi can interact with any editor provided with a client-server mode.
 
Vim as to be compiled with the client-server option, on Ubuntu 8.04 it's ok, for gvim it's usually the case. On Linux Mandrake 9.0. gvim is compiled with the client-server option and Vim is not.
   
 
1-Check that your xdvi version provides the "source-special" functions, by typing '<code>xdvi -version</code>' or '<code>man xdvi</code>'
1-Check the configuration of the source file (file.tex)
 
check you've got the package srcltx.sty and \usepackage{srcltx} (which should be commented out when one finishes and is ready for printing etc).
 
   
 
2-Configuration of xdvi
 
2-Configuration of xdvi
   
 
xdvi has to be called with the following options
 
xdvi has to be called with the following options
 
 
<pre>
 
<pre>
 
xdvi -editor 'gvim --remote-wait +%l %f' file.dvi &
 
xdvi -editor 'gvim --remote-wait +%l %f' file.dvi &
Line 168: Line 183:
 
(or with 'xterm -e vim --remote-wait +%l %f' if Vim has been compiled with the client-server option).
 
(or with 'xterm -e vim --remote-wait +%l %f' if Vim has been compiled with the client-server option).
   
To make it easier to use you can define an environement variable XEDITOR to set the value of 'editor' or add the following line in your .Xdefaults xdvi.editor: gvim --remote-wait +%l %f Launch 'xrdb -load ~/.Xdefaults' to make sure that xdvi.editor is set to the good value. If you have defined such a variable, xdvi will always be launched with the -editor option. To avoid this unsafe behavior, launch 'xdvi -safer'.
+
To make it easier to use you can define an environment variable XEDITOR to set the value of 'editor' or add the following line in your .Xdefaults xdvi.editor: gvim --remote-wait +%l %f Launch 'xrdb -load ~/.Xdefaults' to make sure that xdvi.editor is set to the good value. If you have defined such a variable, xdvi will always be launched with the -editor option. To avoid this unsafe behavior, launch 'xdvi -safer'.
   
 
3-Conversely, if you call xdvi within gvim with the -sourceposition option, cursor is placed in the dvi file on the corresponding position.
 
3-Conversely, if you call xdvi within gvim with the -sourceposition option, cursor is placed in the dvi file on the corresponding position.
   
 
Syntax is:
 
Syntax is:
  +
<pre>
 
xdvi -sourceposition l:cfile.tex file.dvi
  +
</pre>
   
 
<code>l</code> is the line number, <code>c</code> is the column number
xdvi -sourceposition l:cfile.tex file.dvi
 
 
l is the line number, c is the column number
 
   
Be careful: there is no space between "c" (column number) and file.tex.
+
Be careful: there is no space between "<code>c</code>" (column number) and file.tex.
   
 
To make it easier to use, you can do the following.
 
To make it easier to use, you can do the following.
   
First create a file named for example "xdvi_source.vim" with following lines.
+
First create a file named for example <code>xdvi_source.vim</code> with following lines.
 
 
<pre>
 
<pre>
 
" This script calls xdvi source and puts cursor in xdvi viewer at
 
" This script calls xdvi source and puts cursor in xdvi viewer at
Line 190: Line 205:
 
</pre>
 
</pre>
   
Then launch the following command within gvim editing the .tex source file. Pressing simultaneously <CTRL> and -> will open the dvi file at the right position:
+
Then launch the following command within gvim editing the .tex source file. Pressing simultaneously Ctrl and &rarr; will open the dvi file at the right position:
  +
<pre>
 
:noremap <buffer> <C-Right> :so xdvi_source.vim<CR>
  +
</pre>
   
:noremap <buffer> <C-Right> :so xdvi_source.vim<CR>
 
 
==Comments==
 
 
Seems it doesn't work for multiple tex source files.
 
Seems it doesn't work for multiple tex source files.
 
----
 
If you do not have the LaTeX package "srctex", try compling your file with:
 
 
latex --src [your_file.tex]
 
 
which works for me
 
   
 
----
 
----
 
You don't actually need to create that extra file (I prefer my directories to be 'clean' and I always forget to copy the necessary files when starting a new document in a new directory). You can just type:
 
You don't actually need to create that extra file (I prefer my directories to be 'clean' and I always forget to copy the necessary files when starting a new document in a new directory). You can just type:
  +
<pre>
 
:noremap <buffer> <C-Right> :exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"<CR>
+
:noremap <buffer> <C-Right> :exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"<CR>
  +
</pre>
   
 
The problem I run into very often, though, is that I often split my LaTeX source into multiple files (usually one per chapter). The problem is that
 
The problem I run into very often, though, is that I often split my LaTeX source into multiple files (usually one per chapter). The problem is that
  +
<pre>
 
"%:r.dvi"
  +
</pre>
   
 
is than usually wrong (e.g. it should be book.dvi, while the file being edited is chapter1.tex). I think it should be possible to check for files in the directory containing the pattern "{include}\|{input}\{%<" in which case it is PROBABLY this file that will result in the dvi. No way to be sure though, so it is probably best to have a texrc file for every project (extra file, darn!).
"%:r.dvi"
 
 
is than usually wrong (e.g. it should be book.dvi, while the file being edited is chapter1.tex). I think it should be possible to check for files in the directory containing the pattern "{include}\|{input}\{%<" in which case it is PROBABLY this file that will result in the dvi. No way to be sure though, so it is probably best to have a texrc file for every project (extra file, darn!)
 
   
 
If it doesn't work with previous tips, getting xdvi work without support for multiple couple xdvi/vim works by adding:
  +
<pre>
 
:let g:Tex_ViewRule_dvi = 'xdvi -editor "vim --servername vimtex --remote +\%l \%f"'
  +
</pre>
  +
To your .vimrc file and aliasing "vim" to "vim --servername vimtex"
 
----
 
----
For kdvi the command should read:
 
   
  +
I split my LaTeX source into multiple files and directories. I use a main directory with the main .tex file and a tree of directories for each chapter. To fix this tip I used:
kdvi file:name.dvi#src:lname.tex
 
 
where l is the linenumber and name is the filename
 
normal way would be :
 
   
  +
<pre>
  +
:map \ld :execute '!cd ' . expand(Tex_GetMainFileName(':p:h')) . ' && xdvi -editor "gvim --servername 'v:servername' --remote-wait +\%l \%f" -sourceposition ' . line(".") . substitute(expand('%:p'),expand(Tex_GetMainFileName(':p:h')).'\/','','') . " " . expand(Tex_GetMainFileName(':p:r')) . ".dvi &" <CR><CR>
  +
</pre>
 
----
 
----
  +
If it doesn't work with previous tips, getting xdvi work without support for multiple couple xdvi/vim works only by adding :
 
  +
===kdvi===
 
For kdvi the command should read:
 
<pre>
 
<pre>
 
kdvi file:name.dvi#src:lname.tex
:let g:Tex_ViewRule_dvi = 'xdvi -editor "vim --servername vimtex --remote +\%l \%f"'
 
 
</pre>
 
</pre>
  +
To your .vimrc file
 
 
where <code>l</code> is the linenumber and <code>name</code> is the filename.
  +
 
==Comments==

Latest revision as of 03:03, 2 July 2014

Tip 225 Printable Monobook Previous Next

created 2002 · complexity basic · author Dimitri Antoniou · version 6.0+


Vim can interact with the tricks that the latest xdvi or kdvi does:

  • If one clicks at some place in xdvi (usually Ctrl+Button1), Vim automatically jumps to the corresponding line in the LaTeX source file ("reverse search")
  • Also, from inside Vim, one can jump to the corresponding line in xdvi which becomes highlighted ("forward search").

First of all, the latex document need to tell the latex compiler to set marks in the dvi file. Only put:

\usepackage{srcltx}

in the preamble of your latex document, or compile with:

latex --src [your_file.tex]

It works perfectly well with Vim or gvim on one side and xdvi on the other side, even with multiple couple (vim, xdvi). It works also fine with kdvi but can be a little less "smooth".

With xdvi[]

It's very simple. In your .vimrc file, add at the end:

:map \ld :execute '!xdvi -editor "vim --servername 'v:servername' --remote +\%l \%f" -sourceposition ' . line(".") . expand("%") . " '" . expand(Tex_GetMainFileName(':r')) . ".dvi' >/dev/null&" <CR><CR>

and in your .bashrc:

alias vim='vim --servername vimtex'

The first allows the forward search by \ld in normal mode.

To allow the reverse search, Vim has to be opened with vimtex servername; that's the reason for the second line. (I don't use the normal shortcut \ls as that doesn't allow me to use the v:servername variable, see end of this tip.)

Keep in mind that any other program that communicates with Vim server should be aware of the name change (for example jabref). A little script like ouvre can avoid to systematically name the Vim server "vimtex".

Note: On my system (Ubuntu 8-10, with the latex-suite installed via vim-addon-manager) this works, but only if I substitute 'gvim' for 'vim'. Also, for things to work I must, in order, 1) Open my tex file with gvim, 2) Open my dvi file with the command \ld 3) reverse-search using Ctrl + left-mouse-click.

With kdvi[]

If you run it on gnu/linux, I've made a little script to do the work for you (for use with Vim): install_fsearch_kdvi.sh but this doesn't allow running multiple couples of (vim, kdvi). The tips for xdvi would apply, but I've no more time to set it.

Then in kdvi in "configuration> configure kdvi > dvi specificity" set Editor to "vim".

You can then forward search in Vim or gvim by \lf in normal mode.

If you want to use it from gvim only, in the script change:

echo "alias vim='vim --servername KDVI'" >> ~/.bashrc

to

echo "alias gvim='gvim --servername KDVI'" >> ~/.bashrc

It works by a little script in your ~/bin/ directory.

Here is the install script:

#!/bin/bash
script_name=~/bin/fsearch_kdvi.sh
if [[ ! -e ~/bin ]] ; then
mkdir ~/bin/
fi
# setting the script for forward search
echo "#"'!'"/bin/bash" > $script_name
echo "doc_dvi=\${1%.tex}.dvi" >> $script_name
echo "ligne=\$2" >> $script_name
echo "doc_partie=\$3" >> $script_name
echo "kdvi -u file:\$doc_dvi\#src:\$ligne\$doc_partie &" >> $script_name
echo "exit 0" >> $script_name

chmod +x $script_name

# setting of vim for forward search
echo "\" \" To use kdvi forward search, comment it if you don't want to." >> ~/.vimrc
echo ":map \\lf :execute \""'!'"$script_name \". Tex_GetMainFileName()\" \". line(\".\")\" \".expand(\"%\")\"& \" <CR><CR> " >> ~/.vimrc

echo "# To use reverse search with kdvi" >> ~/.bashrc
echo "alias vim='vim --servername KDVI'" >> ~/.bashrc

exit 0

Windows tip[]

If you use the MikTeX distribution on Win32, you can play the same game with Vim and yap. I use the following with Vim 6.0 and (old) MikTeX 1.20b.

From my Vim script for tex files:

execute '!start yap -1 -s' line(".") . expand("%:t") expand("%:p:r")

(Of course, I have a :map and :menu to do this.) This expands to something like:

!start yap -1 -s 1353foo.tex c:\path\to\foo

In yap, from the View/Options panel, choose the "Inverse Search" tab and enter:

gvim --remote +%l %f

in the "Command line" box. This can probably be improved: doesn't the installer put a .bat file somewhere?


The following mapping may also be useful (in one line):

map _g :exe 'silent !xdvi -editor "vim --servername ' . v:servername . ' --remote +\%l \%f" -sourceposition ' . line (".") . expand("%") . " " . expand("%:r") . ".dvi &" \| redraw!<CR>

It starts up an xdvi (if necessary) and does a forward search. Reverse search will jump to the location in the same Vim.


As a followup to benji's excellent tip for yap, (win32) the command :!start as opposed to :! does a kind of fork, so Vim won't wait for the executed program to finish.

That is, type:

exe 'silent !start yap -1 -s' line(".") . expand("%:t") expand("%:r") .'.dvi'

so you don't have to close yap before Vim becomes responsive again. See :help :!start.


I make use of the above a lot, and it usually works great. However, to handle spaces in the file path, it needs a little modification:

exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'

The corresponding mapping (to _g) is:

map _g :exe 'silent !start yap -1 -s' line(".") . expand("%:t") '"' . expand("%:r") . '.dvi' . '"'<CR><CR>

I am using the following in my ~/.Xdefaults:

xdvi.editor: gvim --servername %f --remote-silent +%l %f

With the advantage that I can have multiple Xdvi instances with different files and they all know, what Vim they have to address to.

Also, you may have multiple Xdvi instances with the same file and they will all interact with the same Vim.


There's not clientserver support on vanilla Vim [to be verified as it works well now with Vim].


Problem solving[]

This part has been partly reviewed, other contributors welcome.

0-Check the configuration of the source file (file.tex)

Check you've got the package srcltx.sty and \usepackage{srcltx} (which should be commented out when one finishes and is ready for printing etc).

If you do not have the LaTeX package srctex, try compiling your file with:

latex --src [your_file.tex]

which works for me.

xdvi[]

Forward and reverse search only works for quite recent xdvi versions (>= 22.38), (or recent Unix/Linux versions), xdvi can interact with any editor provided with a client-server mode. Vim as to be compiled with the client-server option, on Ubuntu 8.04 it's ok, for gvim it's usually the case. On Linux Mandrake 9.0. gvim is compiled with the client-server option and Vim is not.

1-Check that your xdvi version provides the "source-special" functions, by typing 'xdvi -version' or 'man xdvi'

2-Configuration of xdvi

xdvi has to be called with the following options

xdvi -editor 'gvim --remote-wait +%l %f' file.dvi &

(or with 'xterm -e vim --remote-wait +%l %f' if Vim has been compiled with the client-server option).

To make it easier to use you can define an environment variable XEDITOR to set the value of 'editor' or add the following line in your .Xdefaults xdvi.editor: gvim --remote-wait +%l %f Launch 'xrdb -load ~/.Xdefaults' to make sure that xdvi.editor is set to the good value. If you have defined such a variable, xdvi will always be launched with the -editor option. To avoid this unsafe behavior, launch 'xdvi -safer'.

3-Conversely, if you call xdvi within gvim with the -sourceposition option, cursor is placed in the dvi file on the corresponding position.

Syntax is:

xdvi -sourceposition l:cfile.tex file.dvi

l is the line number, c is the column number

Be careful: there is no space between "c" (column number) and file.tex.

To make it easier to use, you can do the following.

First create a file named for example xdvi_source.vim with following lines.

" This script calls xdvi source and puts cursor in xdvi viewer at
" the position corresponding to the position in the source file
:exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"

Then launch the following command within gvim editing the .tex source file. Pressing simultaneously Ctrl and → will open the dvi file at the right position:

:noremap <buffer> <C-Right> :so xdvi_source.vim<CR>

Seems it doesn't work for multiple tex source files.


You don't actually need to create that extra file (I prefer my directories to be 'clean' and I always forget to copy the necessary files when starting a new document in a new directory). You can just type:

:noremap <buffer> <C-Right> :exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"<CR>

The problem I run into very often, though, is that I often split my LaTeX source into multiple files (usually one per chapter). The problem is that

"%:r.dvi"

is than usually wrong (e.g. it should be book.dvi, while the file being edited is chapter1.tex). I think it should be possible to check for files in the directory containing the pattern "{include}\|{input}\{%<" in which case it is PROBABLY this file that will result in the dvi. No way to be sure though, so it is probably best to have a texrc file for every project (extra file, darn!).

If it doesn't work with previous tips, getting xdvi work without support for multiple couple xdvi/vim works by adding:

:let g:Tex_ViewRule_dvi = 'xdvi -editor "vim --servername vimtex --remote +\%l \%f"'

To your .vimrc file and aliasing "vim" to "vim --servername vimtex"


I split my LaTeX source into multiple files and directories. I use a main directory with the main .tex file and a tree of directories for each chapter. To fix this tip I used:

:map \ld :execute '!cd ' . expand(Tex_GetMainFileName(':p:h')) . ' && xdvi -editor "gvim --servername 'v:servername' --remote-wait +\%l \%f" -sourceposition ' . line(".") . substitute(expand('%:p'),expand(Tex_GetMainFileName(':p:h')).'\/','','') . " " . expand(Tex_GetMainFileName(':p:r')) . ".dvi &" <CR><CR>

kdvi[]

For kdvi the command should read:

kdvi file:name.dvi#src:lname.tex

where l is the linenumber and name is the filename.

Comments[]