Embed vim settings in file

Vim

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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 - Vim

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 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionkfl62View Question on Stackoverflow
Solution 1 - VimRickView Answer on Stackoverflow
Solution 2 - VimAndrew_1510View Answer on Stackoverflow
Solution 3 - VimZsolt BotykaiView Answer on Stackoverflow