I want to disable autoindent and smartindent for LaTeX so I did

:set noai noci nosi

When I open a brand new mwe.tex, filetype=plaintex and there is no auto indent magic.

When I then enter some code, such as \begin{frame}\end{frame}, save and reopen the file, filetype=tex, colours have changed, and... there is what to me looks like both auto indent and smart indent going on:

  • I start typing \begin{frame} at the beginning of the line, so far so good
  • I press enter, and the cursor is indented by four spaces, despite setting noai, noci, and nosi. At this point, :set shows:
--- Options ---
  background=dark     helplang=en         shiftwidth=4        ttyfast
  commentstring=%%s nomodeline            showmatch           ttymouse=xterm
  expandtab           modified            suffixesadd=.tex
  filetype=tex        ruler               syntax=tex
  foldmethod=indent   scroll=34           tabstop=4
  comments=sO:% -,mO:%  ,eO:%%,:%
  includeexpr=substitute(v:fname, '^.\{-}{\|}.*', '', 'g')
  • I type \end{frame at the indented base. After I add a }, it gets automatically dedented (with a fraction of a second delay).

From :scriptnames, I can tell there are scripts loaded at /usr/share/vim/vim80/indent.vim, /usr/share/vim/vim80/syntax/tex.vim, /usr/share/vim/vim80/ftplugin/tex.vim, and /usr/share/vim/vim80/indent/tex.vim. So it looks like there is a script overriding the standard vim settings. How do I configure the behaviour of this script?


'indentexpr' has the highest priority of how vim can automatically indent lines.

:h 'indentexpr':

When this option is not empty, it overrules the 'cindent' and 'smartindent' indenting.

Your value is indentexpr=GetTeXIndent().

Customize GetTeXIndent()

The behavior of GetTeXIndent() can be customized by a few variables (e.g. g:tex_indent_brace or g:tex_indent_items). They are documented in-source in $VIMRUNTIME/indent/tex.vim.

If you only want to disable the indentation after \begin{frame} but keep indenting other code, you can put in your vimrc

let g:tex_noindent_env = 'document\|verbatim\|lstlisting\|frame'

This variable is also respected by Tex_CalcIdent() of vim-latex and BuckyTeXIndent() of vim-bucky.

Vimtex user: Customize VimtexIndentExpr()

vimtex provides its own indentation function VimtexIndentExpr(). This function can be customized with a similar option g:vimtex_indent_ignored_envs which, however, is a list of names

let g:vimtex_indent_ignored_envs = ['document', 'verbatim', 'lstlisting', 'frame']

Disable indentation completely

:set indentexpr=

Permanent vim setting

If you want to set indentexpr= permanently in your vim config, see the question

How can I change the default indentation based on filetype?

and its answers. Some recommend to not use autocmds but to place

setlocal indentexpr=

into a file such as ~/.vim/after/indent/tex.vim which is always sourced by vim and has the last word.

  • 1
    Of note, these can (and should) be set locally. Also, these options won’t persist—adding them to an ftplugin can help this.
    – D. Ben Knoble
    Jul 10 '19 at 3:45

Within your .vimrc file, add the line

autocmd FileType plaintex,tex,context setlocal indentexpr=


  1. autocmd automatically applies the setup when criterion is met
  2. FileType is the criterion to be met (for files of certain type)
  3. plaintex,tex,context are the common filetypes recognized by vim (see Vim documentation)
  4. setlocal indentexpr= sets the required indent to be nothing
  • @D.BenKnoble Done! Please feel free to improve if necessary!
    – zyy
    Oct 20 '21 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.