I use Vim to write Latex code and I would like to have autoindent when adding environments. I am aware of the smartindent capabilities that can be toggle on and off by inspecting the $VIMRUNTIME/indent/tex/tex.vim file. When I type \section{...} and hit enter, I would like the cursor to be automatically indented:

\section{First section}
    This is a new section.

Also, I would like to avoid using plugins if possible.

Is there a built-in way to do so?

  • 2
    I don't think that indenting text in sections is good style. Indenting text in environments and continued commands and such seems sensible and in good style. But sections? It could lead to very high indent levels! E.g., indent wiith four spaces per indent in \part, \chapter, \section, \subsection, then perhaps \begin{itemize} would give 20 spaces indentation! Just saying. – Karl Yngve Lervåg Apr 3 '20 at 6:50
  • 1
    You can write an \indentexpr yourself to get the desired functionality. It requires some vimscript knowledge to do it, but it is all quite well documented, see :help indentexpr. – Karl Yngve Lervåg Apr 3 '20 at 6:51

Your Answer

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

Browse other questions tagged or ask your own question.