Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 need different tab widths for different files when using Vim. Is there a way to store this information in the file, and let Vim apply the setting automatically?

share|improve this question
up vote 7 down vote accepted

Depending on what fits your situation you could look into customizing the filetype plugins (if you want tabstop settings by filetype) or enable modelines and accept the accompanying security risks if the settings are specific to individual files.

For the filetype approach, as an example I have the following in ~/.vim/after/ftplugin/python.vim:

setlocal expandtab softtabstop=4 shiftwidth=4
share|improve this answer
Modelines is what I was looking for. Thanks! – user4518 Nov 11 '11 at 10:12

Your Answer


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