4

I edit a LaTeX file, and for some commands Vim does auto indenting.

I would like to switch it off.

Consulting:

https://www.serverwatch.com/guides/automatic-indenting-vim/

I tried:

:filetype indent off

and:

:set paste

but they did not work, Vim sometimes puts a leading tab before my commands.

How can I switch off auto indenting for my LaTeX files?

1 Answer 1

4

To disable auto indentation you can do:

:set noautoindent
:set indentexpr=

If you want to make automatic for all LaTeX files you could add a tex.vim file within ~/.vim/after/indent/ folder with the following content:

setlocal noautoindent
setlocal indentexpr=
6
  • It did not work. I don't know which part of vim does this, but when I write a command starting with backslash, write the command name and enter an opening curly brace, vim adds a leading tab to the line.
    – Gergely
    Commented Apr 11, 2023 at 10:10
  • 1
    I have reproduced your problem and adapted the solution accordingly :-) Commented Apr 11, 2023 at 10:40
  • 1
    I have created the tex.vim file in the mentioned directory and now indentation is reliably turned off
    – Gergely
    Commented Apr 11, 2023 at 12:18
  • 1
    Is there a particular reason to put this below the after folder? I don't seem to need that ... ? (I.e., the indent folder on level higher seems to work.)
    – Alan
    Commented Sep 19, 2023 at 16:29
  • 1
    @Alan: The ~/.vim/indent/tex.vim is executed before $VIMRUNTIME/indent/tex.vim that is executed ~/.vim/after/indent/tex.vim. If you want to be sure to override what is done $VIMRUNTIME/indent/tex.vim a solution is to make it in ~/.vim/after/indent/tex.vim. Of course if nothing is done in $VIMRUNTIME/indent/tex.vim it is ok to do the change in ~/.vim/indent/tex.vim :-) Commented Sep 19, 2023 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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