Vim logo vim online Vim Book Ad

basic Tip #331: modline magic...

 tip karma   Rating 16/9, Viewed by 994 

created:   September 22, 2002 14:35      complexity:   basic
author:   Alex A. Naanou      as of Vim:   5.7

  One  of the  things about  vim that  are both  quite simple  yet very
useful is that you can store  by-file settings... that is each file can
contain settings specific to it. this  thing is called a modline (:help
modline). though this  is limited to only the  'set' command arguments,
you can do allot of local to  file things like the indent type, folding
method and so on.                                                      

the syntax is as follows:

// vim:set ts=4 sw=4 nowrap:

or

/* vim:noai:ts=2:sw=4: */

  The modlines can be contained in comments so as to not interfere with
the file  syntax (shown here  for C/C++). these  lines are read  by vim
when it loads the  file, and they can either be in the  first or last 5
lines (by default).                                                    

refer to ':help modline'

//and a happy 20th birthday to the good old smiley!! :-)

 rate this tip  Life Changing Helpful Unfulfilling 

<<how to stop auto indenting | make footnotes in vim >>

Additional Notes

[email protected], September 22, 2002 20:18
That's modeline, and :help modeline
[email protected], September 23, 2002 1:28
Speeking of modelines I find it handy to have a very primitive menu entry to insert my normal modeline for me:

amenu  Fe&ral;'s.Insert\ a\ VIM\ modeline <Esc><Esc>ggOvim:ff=unix ts=4 ss=4<CR>vim60:fdm=marker<esc>gg

This will net you a (I think proper) modeline at the start of the file like so:

vim:ff=unix ts=4 ss=4
vim60:fdm=marker
hermitte at free.fr, September 25, 2002 7:11
BTW, this mecanism can be extended to 'let'. Cf. for instance : vimscript#83
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo