# Vim indent in LaTeX align goes crazy

\begin{align*}
u(x, t) &= \frac a2 \int_0^t \dif s \int_{x-a(t-s)}^{x+a(t-s)} \dif y \sin(\omega y) \\
\end{align*}


Then I go on and enter the second line, Vim aligns the &, which is sort of neat. It all goes well just before the first }:

\begin{align*}
u(x, t) &= \frac a2 \int_0^t \dif s \int_{x-a(t-s)}^{x+a(t-s)} \dif y \sin(\omega y) \\
&= \frac{1
\end{align*}


Then I enter the } and it does this:

\begin{align*}
u(x, t) &= \frac a2 \int_0^t \dif s \int_{x-a(t-s)}^{x+a(t-s)} \dif y \sin(\omega y) \\
&= \frac{1}
\end{align*}


With every }, it gets indented a little more. After a while, the whole align* is completely unreadable.

How can I make Vim stop doing this?

My complete .vimrc

-
I have similar issues with html files, would be nice to know how to deal with this. You can try :set noautoindent in the meantime – Ярослав Рахматуллин Oct 27 '12 at 18:03
I use filetype indent, that should do HTML correctly. – Martin Ueding Oct 27 '12 at 18:26

I had the same problem. gvim ignored my noautoindent settings in my .vimrc. I checked the settings in a .tex file with :verbose set ai? and it revealed that autoindent was enabled through the vim-latex plugin. To disable indentation after braces put the following code in your .vimrc (or .vim/after/ftplugin/tex.vim):

let g:tex_indent_brace=0


If you do NOT use vim-latex, try to find out which script is causing the indentation.

-
This seems to have fixed it. It was set to 1. – Martin Ueding Nov 25 '12 at 20:57

I solved the problem via :set expandtab (the workaround of panos did not work for me). It seems, that the vim plugin get confused, when you have tabs and spaces mixed in the file. So I set in my .vimrc:

autocmd Filetype tex setlocal expandtab


See http://vim.wikia.com/wiki/Converting_tabs_to_spaces for details about tabs and spaces in vim.

-