Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just spent a few hours working through indentation pains with javascript, and the conclusion I came to is <strong>don't remove <code>filetype indent on</code> from your vimrc!</strong></p> <p>This setting provides the best smart indentation for multiple file types. If you're getting bad results with this, there's likely a configuration issue at hand.</p> <h1>File Specific Indent Settings</h1> <p>So if you're like me, you probably had <code>filetype indent on</code> in your vimrc and had no idea what it was doing.</p> <p>All this setting does is tell vim to look for files with filetype-specific indent rules. There are a few places it looks, but there are probably only two that you'd be interested in.</p> <ol> <li><code>$VIMRUNTIME/indent/</code></li> <li><code>~/.vimrc/after/indent/</code></li> </ol> <p>The first place holds the default indent rules that come with vim. If you were to set <code>filetype indent on</code> on a fresh vim installation, this is where all the smart indenting would come from. For example, when you open a file called <code>index.html</code> in would get the rules from <code>$VIMRUNTIME/indent/html.vim</code>.</p> <p>In my experience, these default rules are pretty darn good, but they can get messed up by other settings.</p> <p>The second place (the <code>after</code> directory) allows you to add settings that will supercede those in the first place. This is nice because you don't have to edit the default files in order to customize them.</p> <h1>Flavors of Indentation</h1> <p>There are a few different indentation options as you've seen, and they don't all play nice together. From the <a href="http://vim.wikia.com/wiki/Indenting_source_code#Methods_for_automatic_indentation" rel="nofollow noreferrer">Vim wiki:</a></p> <h3>autoindent</h3> <blockquote> <p>'autoindent' does nothing more than copy the indentation from the previous line, when starting a new line. It can be useful for structured text files, or when you want to control most of the indentation manually, without Vim interfering. 'autoindent' does not interfere with other indentation settings, and some file type based indentation scripts even enable it automatically.</p> </blockquote> <p>I use <code>filetype indent on</code> and <code>set autoindent</code> in my vimrc, since they work well together. I don't have the others set.</p> <h3>smartindent &amp; cindent</h3> <blockquote> <p>'smartindent' automatically inserts one extra level of indentation in some cases, and works for C-like files. 'cindent' is more customizable, but also more strict when it comes to syntax. 'smartindent' and 'cindent' might interfere with file type based indentation, and should never be used in conjunction with it.</p> <p>When it comes to C and C++, file type based indentations automatically sets 'cindent', and for that reason, there is no need to set 'cindent' manually for such files. In these cases, the 'cinwords', 'cinkeys' and 'cinoptions' options still apply.</p> <p>Generally, 'smartindent' or 'cindent' should only be set manually if you're not satisfied with how file type based indentation works.</p> </blockquote> <h3>indentexpr</h3> <p>Runs filetype indent scripts found in <code>(vimfolder)\indent\\(indentscripts)</code>. It is mentioned in the <a href="http://vimdoc.sourceforge.net/htmldoc/filetype.html" rel="nofollow noreferrer">vim documentation</a> for filetype, alongside the others just mentioned (also, it was the cause of the problem I was having):</p> <blockquote> <p>Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.</p> </blockquote> <h1>Troubleshooting</h1> <p>There's a chance that some rogue plugin is changing your indent settings and that's why you're getting poor results. Luckily <code>verbose</code> will tell you which file was the last to change the option in question.</p> <pre><code>:verbose set autoindent? :verbose set cindent? :verbose set smartindent? :verbose set indentexpr? </code></pre> <p>You may get a result such as</p> <pre><code>indentexpr=SomeMessedUpValue Last set from ~/.vim/bundle/some_plugin/indent/plaintex.vim </code></pre> <p>If that happens, you can move that file, close and open vim, and see if it fixes your problem.</p> <h1>Turning Off Indent Settings for TeX</h1> <p>Maybe the defaults just aren't doing it for you, and you want to disable the indent settings for TeX, but leave all other file types alone. You can easily do so by setting these values to their defaults in a file in the <code>after</code> directory.</p> <p>I don't know much about Tex or LaTex, but when I created a file with the <code>.tex</code> extension and ran <code>:filetype</code> it had the filetype as <code>plaintex</code>. Assuming that this is correct, you'd want to create a file, <code>~/.vim/after/indent/plaintex.vim</code>. In that file:</p> <pre><code>set autoindent&amp; set cindent&amp; set smartindent&amp; set indentexpr&amp; </code></pre> <p>This will set all these values to their defaults whenever you open a <code>.tex</code> file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload