Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've go a bunch of filetype dependent autocommands in my .vimrc, some of which are syntax related.

I'd like to put these in separate file throughout my .vim/ tree, eg. some tex syntax would go in .vim/syntax/tex.vim but when I do this, vim doesn't pick up on them anymore.

I'm guessing that the files aren't read in automatically (as I first expected). What should I do?

share|improve this question
up vote 2 down vote accepted

Did you put the autocommands in those separate files as autocommands? That is, does your ~/.vim/syntax/tex.vim contain lines like this,

au FileType tex set expandtab

or this,

au BufRead,BufNewFile *.tex set expandtab

If so, that's wrong. Vim sources the files in the ftplugin, syntax and indent directories when a file of the file type corresponding to the name of the plugin is opened. If the plugin contains autocommands, those autocommands will be read and executed but the command portion won't be executed until the next time the triggering event occurs.

If you want to make some filetype-dependent setting, put a command like this in the ftplugin for that file type.

setlocal expandtab

Don't put it in an autocommand and do use setlocal rather than just set so that the setting will apply to the buffer containing that file type and not apply to all your Vim buffers.


:help 43.1
:help 41.11


I forgot to answer another part of the question. Vim has three types of filetype-dependent plugins that go in three different subdirectories of ~/.vim: ftplugin, syntax and indent. The indent subdirectory is intended for plugins that affect the indentation of specific file types. The syntax subdirectory is intended for plugins that affect syntax coloring. The ftplugin is intended for plugins that affect behavioral settings such as textwidth, mappings, abbreviations and such.

share|improve this answer
I put stuff in it like this syntax match ... no autocommand, yet it seems as if vim ignores this in ~/.vim/syntax/tex.vim – romeovs May 24 '11 at 15:47
@romeovs: Things to try: :set ft? should show "filetype=tex"; :set rtp? should show a comma-separated list of directories which includes "~/.vim"; :scriptnames should show a list of all the plugins that Vim has sourced since starting up and if you're editing a TeX or LaTeX file, should show that it looked for plugins with the name "tex.vim". – garyjohn May 24 '11 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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