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 work with several languages and markups in vim every day (ruby, python, javascript, CSS, HTML, etc), and would like to have different settings for each buffer when I fire up my editor. How can I detect which syntax is loaded in the current buffer?

Specifically, I really prefer python indent to be 4 spaces, while other languages are find with 2. I've envisioned something like this in my .vimrc file:

if syntax == 'python'
  set softtabstop=4
  set shiftwidth=4
else if syntax == 'html'
  " ...

Anything like that in vim? thanks.

share|improve this question
up vote 5 down vote accepted

Use the FileType autocommand event. See :h autocmd.txt for details.

au Filetype python source ~/.vim/scripts/python.vim
share|improve this answer
Why creating non standard directories ? -> ~/.vim/ftplugin ! – Luc Hermitte Dec 1 '10 at 10:12
Thanks - what I ended up doing is using your idea with some modification: au FileType python set softtabstop=4 | set shiftwidth=4 – sa125 Dec 1 '10 at 10:42

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.