Embed vim settings in file

In some files I can see a commented line, usually the last, with vim settings. Does vim read these settings? If it does, are any limitations of what kind of settings man can put there?


Solution 1:

They're called modelines and while I'm not sure the extent you can go with them, here's a link to the vimtips wiki with some examples:

http://vim.wikia.com/wiki/Modeline_magic

help modeline

from within vim to check out the official docs.

Solution 2:

It's this line of code:

[other chars]<spaces>vim:<spaces>settings

Put it in the first or last few lines of the file, note it needs < spaces >. For example:

# vim: tabstop=2 shiftwidth=2 expandtab

In short version:

# vim: ts=2 sw=2 et

Put one of the above line in the file, in top or bottom lines, done. For more information, use vim help:

:h modeline

Solution 3:

You can check out in the online manual: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline

And this faq item also refers to it: http://vimdoc.sourceforge.net/htmldoc/vimfaq.html#19.5