sponsor Vim development Vim logo Vim Book Ad

auctex.vim : macros for latex

 script karma  Rating 484/141, Downloaded by 14008  Comments, bugs, improvements  Vim wiki

created by
Carl Mueller
 
script type
ftplugin
 
description
This is a large collection of Latex macros, with inspiration
from the emacs package "auctex", among other places.  
Read the file for details;  I have written many comments.

You should freely modify these macros.  Most of them are  
indepent, so nothing will break.  In some places I've provided
alternate versions which are commented out.  If you have good
ideas, contact me and I'll incorporate them.

By popular demand, here is a more extensive description of
the key bindings:
http://www.math.rochester.edu/people/faculty/cmlr/Latex/auctex-vim-keybindings

There is also Vim-LaTeX,
http://vim-latex.sourceforge.net
It is a more extensive package, developed by a group, and I have
contributed most of my ideas to this project.  You might prefer
my script if you like something smaller, with parts that are (mostly)
independent and easy to modify.

Briefly,

In normal mode, F1 - F4 will insert latex templates, unless they are
already there in the file.  You have to provide these templates yourself.

In insert mode, F1 - F5 will insert environments such as \begin{..} \end{..}.

C-S-F1 through C-S-F5 will alter existing environments.

(), $$, [], \[\], {}, \{\}, && are inserted in matching pairs.

Outside of a math environment, tab does word completion,
or gives a tab if the previous character is a space or
a line beginning.  Within a math environment,
tab moves you between parentheses or to the end of the
environment.

Many Latex commands are bound to the ` key.  (This comes from auctex).
For instance, \alpha is bound to `a, and \infty is bound to `8.
\frac{}{} is bound to `/  .

Menu items allow you to change or delete matching pairs of brackets,
as well as insert \left..\right automatically.  

Now pressing <Insert> twice will also allow modification of brackets, according
to a menu that appears at the bottom.

In normal mode, K runs latex, takes you to the position of the first error (if any),
and displays the error message with highlighting.

To get \mathbf{R}, type r<Insert>b.  To get \mathcal{R}, type r<Insert>c.
<Insert>s produces \sqrt{}.  Capital letters are more common, but you can
still get \mathbf{x} by typing X<Insert>b.  Same for \mathcal.

Some macros are polymorphic.  For instance, when preceded by bracket,
<Insert>l will insert \left..\right around the brackets.  Otherwise it
will insert \label{} and position the cursor in between the {}.
Likewise, <Insert>c will produce \cite{} when preceded by a blank or at
the beginning of the line;  but, for example, b<Insert>b will produce \mathbf{B}.

There are "smart quotes".  That is, typing " will produce a `` if there is
a space before the ", and will produce '' otherwise.

You can embrace the visual region with () by typing `(.  This works
for other kinds of parentheses, too, as well as $$ and &&.

Long lines are automatically split up to keep $..$ (math expressions)
on the same line.

There are several abbreviations, such as \b for \bigskip.

You can add your own macros, the macro key is ;

Inspired by LaTeX-Suite, the tab key has some new uses.  Inside \ref{}, it opens
a subwindow with the reference keys.  Pressing enter will insert that reference.  
Ditto for \cite{}, the subwindow will show either your bibitem entries (if any) or
your bibtex file.  Pressing enter within the bibtex reference will insert the proper
citation key.
 
install details
Put the file in the directory ~/.Vim, and include the following line in your .vimrc file:

autocmd Filetype tex source ~/.Vim/auctex.vim
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
auctex.vim 2.2.18 2016-12-12 8.0 Carl Mueller Running latex no longer pollutes the screen with output.
auctex.vim 2.2.17 2015-10-09 7.4 Carl Mueller Fixed a bug in the reference insertion feature.
auctex.vim 2.2.16 2015-09-18 7.0 Carl Mueller When you make a tex error, the cursor automatically goes to the position of the error.  This feature didn't work with long lines, now it's corrected.
auctex.vim 2.2.15 2014-06-07 7.4 Carl Mueller Now reference and citation insertion works correctly.
auctex.vim 2.2.14 2014-06-06 7.4 Carl Mueller Now the page is centered after reference or citation insertion.
auctex.vim 2.2.13 2014-06-06 7.4 Carl Mueller Improved <F7> proof macro.  Also, <Insert>i now puts in a <CR> before \item, so you can use it at the end of the previous \item.
auctex.vim 2.2.12 2014-06-02 7.4 Carl Mueller Now after a successful latex compilation, the cursor is centered in the window.
auctex.vim 2.2.11 2012-07-06 7.3 Carl Mueller Inserting environments "description", "enumerate", and "itemize" now results in "\item" appearing on the first line of the environment, and the cursor placed correctly.  Removed redundant key bindings <M-Space>, <C-Space>, <C-Tab>, <S-Tab>.
auctex.vim 2.2.10 2012-05-24 7.3 Carl Mueller Now within \cite{}, the tab key only opens the bibtex or reference window when the cursor is just to the right of the left bracket.  Otherwise the cursor is placed to the right outside the brackets.
auctex.vim 2.2.9 2012-05-21 7.3 Carl Mueller Now it is possible to add multiple reference within a \cite{} while in citation mode.  Just go the citation in the lower window and press comma or right click.
auctex.vim 2.2.8 2011-10-16 7.3 Carl Mueller Vim no longer recognizes <S-F1>, <S-F2>, etc.  I'm changing these bindings to <C-S-F1> and so on.  They are used to change environments.
auctex.vim 2.2.7 2011-10-08 7.0 Carl Mueller Changed mathbf and mathcal macros to switch the capitalization of the letter.  This is because capital letters are more common with these commands, so it saves a keystroke.  But if you want  a small letter, you can still get it.
auctex.vim 2.2.6 2010-07-31 7.0 Carl Mueller Fixed bug for changing environments with <S-F5>.
auctex.vim 2.2.5 2010-05-27 7.0 Carl Mueller Some further cleanup
auctex.vim 2.2.4 2010-05-26 7.0 Carl Mueller Slight improvement of the double insert macro of 2.2.3.  Removed corresponding <Tab> key bindings.
auctex.vim 2.2.3 2010-05-25 7.0 Carl Mueller Pressing <Insert> twice now changes brackets in various ways, according to a menu that appears at the bottom.
auctex.vim 2.2.2 2010-05-17 7.0 Carl Mueller Fixed bug in changing environments (perhaps due to changes in vim scripting).
auctex.vim 2.2.1 2009-04-22 7.0 Carl Mueller Fixed small bug when searching for "bibliography".
auctex.vim 2.2 2008-03-02 7.0 Carl Mueller Some bug fixes, especially in breaking lines.
auctex.vim 2.1.4 2008-02-13 7.0 Carl Mueller Various features are faster and better.  For example, ending the line in a period now splits the line if it is too long.
auctex.vim 2.1.3 2008-02-04 7.0 Carl Mueller Speeded up the macro where ".." results in "\ldots" or "\cdots", or just "\dots".
auctex.vim 2.1.2 2008-01-28 7.0 Carl Mueller Suppressed search highlighting that came on in one of the macros, and made another small fix.
auctex.vim 2.1.1 2007-12-31 6.0 Carl Mueller Another improvement to \ref and \cite macros, in line with the Reftex emacs package.
auctex.vim 2.1 2007-11-14 7.0 Carl Mueller Improved citation lookup.  Now pressing tab while in \cite{} will split the window and either view your bibitem entries (if any) or load your bibtex file.  Then you can go to the entry you want, press Enter, and the citation will be copied into \cite{}.  This was inspired by reftex, an emacs package.
auctex.vim 2.0011 2007-10-15 7.0 Carl Mueller Yet another small improvement in the tab map.
auctex.vim 2.0010 2007-10-04 6.0 Carl Mueller Made a small improvement in the tab key map.
auctex.vim 2.0009 2007-09-07 7.0 Carl Mueller One small change.  To change an environment, type S-F1 through S-F5.  This replaces the control key, which is used for other things in KDE.  Otherwise, there seems to be no reason to change the script, please send suggestions if you think otherwise.
auctex.vim 2.0008 2004-07-30 6.0 Carl Mueller Inspired by LaTeX-Suite, the tab key has some new uses.  Inside \ref{}, it opens a subwindow with the reference keys.  Pressing enter will insert that reference.
Ditto for \cite{}.  Pressing enter within the bibtex reference will insert the proper
citation key.
auctex.vim 2.0007 2004-03-18 6.0 Carl Mueller Fixed a bug involving changes of environment.  (Control-F5)
auctex.vim 2.0006 2003-07-11 6.0 Carl Mueller The tab key now does word completion
outside of a math environment, or
produces a tab at the beginning of the
line or if the previous character is a
space.  Within a math environment, it takes you to the next set of
parentheses, or to the end of the
environment.  Other small fixes.
auctex.vim 2.0005 2002-12-06 6.0 Carl Mueller Fixed the last bug in this version
(I hope).
auctex.vim 2.0004 2002-12-02 6.0 Carl Mueller Now running latex automatically
takes you to the error (if any).
Also, corrected a bug.
auctex.vim 2.0003 2002-11-11 6.0 Carl Mueller Fixed a bug in the automatic line
breaking.  Also, the script is now
easier to read and customize.
auctex.vim 2.0002 2002-10-28 6.0 Carl Mueller Fixed a bug
auctex.vim 2.0001 2002-10-23 6.0 Carl Mueller Used the "mapleader" variable to make
it easier to customize some macros.
auctex.vim 2.0 2002-10-04 6.0 Carl Mueller auctex.vim is now compatible with both
latex and amslatex.  See the file for
details.  This mostly affects the function keys, which are used to enter the most common environments.
auctex.vim 1.6.1 2002-09-03 6.0 Carl Mueller Added support for the ampersand macro
in the tabular environment.  Suggested
by Johannes Ranke.
auctex.vim 1.6 2002-07-26 6.0 Carl Mueller Extensive code clean-up, with many
suggestions by Peppe Guldberg.  Various
improvements and fixes.  Some emacs
bindings included for convenience.  
Vi purists can delete these!
auctex.vim 1.5 2002-06-22 6.0 Carl Mueller Fixed the <F5> macro for the entering
environments (thanks to Peppe Guldberg and Torsten Wolf).  Improved the macros
for modifying brackets.  A few other
small changes, too.
auctex.vim 1.01 2001-12-09 6.0 Carl Mueller Corrected a bug in the bracket macros.
auctex.vim 1.0 2001-12-03 6.0 Carl Mueller Initial upload
ip used for rating: 44.220.184.63

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.
   
Vim at Github