3 " Maintainer: Johannes Tanzler <jtanzler@yline.com>
4 " Created: Sat, 16 Feb 2002 16:50:19 +0100
5 " Last Change: Sun, 17 Feb 2002 00:09:11 +0100
6 " Last Update: 18th feb 2002, by LH :
7 " (*) better support for the option
8 " (*) use some regex instead of several '||'.
10 " URL: comming soon: http://www.unet.univie.ac.at/~a9925098/vim/indent/tex.vim
12 " --> If you're a Vim guru & and you find something that could be done in a
13 " better (perhaps in a more Vim-ish or Vi-ish) way, please let me know!
17 " To set the following options (ok, currently it's just one), add a line like
18 " let g:tex_indent_items = 1
21 " * g:tex_indent_items
23 " If this variable is set, item-environments are indented like Emacs does
24 " it, i.e., continuation lines are indented with a shiftwidth.
26 " NOTE: I've already set the variable below; delete the corresponding line
27 " if you don't like this behaviour.
29 " Per default, it is unset.
32 " ----------------------------------------------------------------
33 " \begin{itemize} \begin{itemize}
34 " \item blablabla \item blablabla
35 " bla bla bla bla bla bla
36 " \item blablabla \item blablabla
37 " bla bla bla bla bla bla
38 " \end{itemize} \end{itemize}
41 " This option applies to itemize, description, enumerate, and
46 " Delete the next line to avoid the special indention of items
47 if !exists("g:tex_indent_items")
48 let g:tex_indent_items = 1
51 if exists("b:did_indent") | finish
56 setlocal indentexpr=GetTeXIndent()
58 setlocal nosmartindent
60 setlocal indentkeys+=},=\\item,=\\bibitem
63 " Only define the function once
64 if exists("*GetTeXIndent") | finish
69 function GetTeXIndent()
71 " Find a non-blank line above the current line.
72 let lnum = prevnonblank(v:lnum - 1)
74 " At the start of the file use zero indent.
75 if lnum == 0 | return 0
78 let ind = indent(lnum)
79 let line = getline(lnum) " last line
80 let cline = getline(v:lnum) " current line
82 " Do not change indentation of commented lines.
87 " Add a 'shiftwidth' after beginning of environments.
88 " Don't add it for \begin{document} and \begin{verbatim}
89 ""if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
90 " LH modification : \begin does not always start a line
91 if line =~ '\\begin{\(.*\)}' && line !~ 'verbatim'
92 \ && line !~ 'document'
96 if g:tex_indent_items == 1
97 " Add another sw for item-environments
98 if line =~ 'itemize\|description\|enumerate\|thebibliography'
105 " Subtract a 'shiftwidth' when an environment ends
106 if cline =~ '^\s*\\end' && cline !~ 'verbatim'
107 \&& cline !~ 'document'
109 if g:tex_indent_items == 1
110 " Remove another sw for item-environments
111 if cline =~ 'itemize\|description\|enumerate\|thebibliography'
120 " Special treatment for 'item'
121 " ----------------------------
123 if g:tex_indent_items == 1
125 " '\item' or '\bibitem' itself:
126 if cline =~ '^\s*\\\(bib\)\=item'
130 " lines following to '\item' are intented once again:
131 if line =~ '^\s*\\\(bib\)\=item'