URL:         http://www.math.fu-berlin.de/~guckes/vim/latex.html
URL:         https://www.vim8.org/latex.html (mirror)
Created:     Wed May 29 00:00:00 MET 1996
Last update: Mon Jun 05 12:00:00 MET DST 2000
Vim-5 adds "syntax coloring" as a feature to Vim. The syntax file "tex.vim" should contain the necessary info to colorize your LaTeX commands and show math mode in its own color.

VIM - LaTeX Editing

This text assumes that you use VIM as the editor and some version of LaTeX. Furthermore you should have some "viewer" available to view PostScript files.

	Category	Name		executable
	========        ====            ==========
	Editor		VIM		vim
	Typesetter	LaTeX		latex
	Viewer		GhostView	gv
	Viewer		Xdvi		dvi
WARNING: The macros presented here are usually written Vim's "angle notation" which allows to represent special characters to be written out in letters. This allow to copy&paste; them from the screen (terminal) right onto the command line or into the setup file (vimrc). So you cannot use them with Vi, unless you convert them. Sorry.

Some examples:

<esc> Escape key <c-g> CTRL-G <up> cursor up key <c-leftmouse> Control- left mouse click <s-f11> Shifted function key 11 <m-a> Meta- a ('a' with bit 8 set) <m-a> Meta- A ('A' with bit 8 set) <t_kd> "kd" termcap entry (cursor down key) For more info on the angle notation see ":help <>".
[960529,971208]


Apply LaTeX on current file

The first macro will invoke LaTeX on the current file:
	"   ,rl = run latex (on current file)
	map ,rl :!latex %
If you are not familiar with LaTeX then you should know that it will create several files from the tex file, most notably a log file (file.log) which stores all the messages that you get from LaTeX while processing the file.tex, an auxiliary file (file.aux) to keep references and other information, and the resulting "device indepent" (latex.dvi).

After creating the dvi file you will want to check it, ie display it on screen. The most common program available is "GhostView" which displays PostScript files. So we need to produce a PostScript file ("ps file") from the dvi file first. PostScript files have the extension ".ps".

That next macro creates a ps file from a dvi file:

	"   ,cps = create ps file (from dvi file of current file)
	map ,cps :!dvips %<.dvi -o:!ghostview %<.ps

Abbreviations

Insert environments while you type:
	imap ^e {\em}i
	imap ^b {\bf}i
	imap ^t {\tt}i
	imap ^v \verb++i
TODO:
	map! ]i \item 
	map! ]bi \begin{itemize}\item 
	map! ]ei \end{itemize}
	map! ]be \begin{enumerate}\item 
	map! ]ee \end{enumerate}
	map! ]bd \begin{description}\item[
	map! ]ed \end{description}
	map! ]bc \begin{center}
	map! ]ec \end{center}
	map! [be{\samepage\begin{eqnarray}
	map! [ee\end{eqnarray}}
	map! ]s1 \section{
	map! ]s2 \subsection{
	map! ]s3 \subsubsection{
	map! ]p1 \paragraph{
	map! ]p2 \subparagraph{
	map! ]f \frac{
	map! ]o \overline{
	map! ]u \underline{
	map! ;em bi{\em lea}i 
ab latex \documentstyle[a4]{artikel}
\begin{document}
\input{titel}
\end{document}kki 
" ================= Block Macros =========================
" =. macro - creates line of "."s of length = column position
map =. mx:t.
`xjaxD:s/././g
"
" =* macro - used by block macros: creates line divider: \(...\)\(...\)
map =* `a=.xI:s/^A/\\(&\\)\\(/"xdd`b=.@xA\)
"
" *d macro - delete block from `a (top left) to `b (bot right)
map *d =*I:'a,'bs/A\(.*\)/\1\3/"xdd@x
"
" *D macro - delete from column `a to end of line, over lines 'a,'b
map *D `a=.xI:'a,'bs/\(A\).*/\1/"xdd@x
"
" *y macro - yank `a,`b block onto new lines ('z to 'a-1)
map *y =*I:'a,'bg/^/t'a-1|'a-1s/A.*/\2/"xdd'aOmz@x'zddmz
"
" *t (*T) macro - copy `a,`b block to after (before) cursor
map *t my*y`y=.=t
map *T my*y`y=.x=t
" this should work, but may give "Can't undo in global" message (vi bug?)
map =t I:'z,'a-g/[\\&~?]/s//\\&/g
:'z,'a-s/\(.*\)/s?\\(A\\)?\\1\1?/"ydd@y:'z,'a-g/^/d x|'y@x|'y+ma y
" this works, but is slower and ends with messy "Undefined mark" message
" (these are in ~/.viblock2, so if above fails do ":so ~/.viblock2" and redo)
"map =t I:'z,'a-g/[\\&~?]/s//\\&/g
:'z,'a-s/\(.*\)/s?\\(A\\)?\\1\1?/"ydd@y'akmx*@
"map *@ :'xma x|'zd x|ma z|'y@x
jmy*@

VI specific stuff

If you do not have VIM (shame on you!) then you have to use a few UNIX tools to achieve what you want:

Stripping extensions is done with "basename":

	"run dvips on document
	map =d :!dvips `basename % .tex` ^M:e^M^M
	"
	" run previewer on dvi version of document
	map =pr :!prv `basename % .tex`.dvi ^M^M
	"
	" run previewer on postscript version of document
	map =gv :!gv `basename % .tex`.ps & ^M^M
	"
	" print .ps version of file
	map =ps :!pps `basename % .tex`.ps^M^M

Send feedback on this page to
Sven Guckes [email protected]