How can I include vim settings in source code so that the file is displayed the same way?

8

I vaguely remember that there is a way to store instructions for vim in my file (like tabstop width etc). I'm not speaking of settings in vimrc but of storing those settings with in the file to be edited.

That way the tabstop has always the right width even if I transfer this file to another computer.

However, I can't remember what the magic word is so that vim picks up those settings when loading the file. Any ideas?

Jon

Posted 2011-02-15T13:23:38.200

Reputation: 145

Answers

12

Put a comment with vi: in it, ending with a newline.

/* vi: tabstop=4
*/

If vim doesn't pick this up then you may need to add set modeline to ~/.vimrc. See :h modeline for full details.

Ignacio Vazquez-Abrams

Posted 2011-02-15T13:23:38.200

Reputation: 100 516

Thanks a lot for pointing me into the right direction! It works perfect. Cheers. – Jon – 2011-02-15T13:46:56.853

2You can avoid having to have the closing comment string on a new line by using the "set" form of a modeline, for example: /* vi: set tabstop=4: */ – Heptite – 2011-08-21T20:05:38.233

2I didn't need a new line # vim:et:sts=4:sw=4 – Felipe Alvarez – 2013-10-02T00:12:27.463

1You're welcome: <!-- vi: set sw=4 ts=4: --> – Andrejs Cainikovs – 2014-02-23T16:04:42.863