Vim modelines

Type
Status
Concerning

I edit a few different types of files with a few different indentation styles. Now, my favorite text editor is vim, and that supports using a config file to set your indentation style, but since I use a few of them, one config file won't work for me. Now, I'm sure you could also set a different style per filetype -- for example, python indents two spaces, C uses tabs displayed as four spaces. But that doesn't work, because different projects sometimes choose different styles, even though they use the same type of file.

Well, it turns out that you can store your preferred indentation setup (or any other vim commands) right there in the file you're working on. I've been aware of this for awhile, because I've seen the commands in files I've worked on. But I always forget the exact syntax of it. I usually end up looking for a file that has this, and then copying it out and tweaking it.

But now I know the magic word, so I could google it. These things are called "modelines". Here's a comprehensive howto on the vim wiki:
Modeline Magic

In short, here's how to do it (in a C file):

  1. // vim: ts=4:noet:sw=4

That's "tabstop = 4", "do not expand tabs (i.e. use tabs not spaces)", and "shift by four characters when using the >> command".

There. Now I know how to look this stuff up.

Your rating: None Average: 2 (5 votes)

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
   __       _             _               
/ _| __| | __ _ (_) __ _ ___
| |_ / _` | / _` | | | / _` | / __|
| _| | (_| | | (_| | | | | (_| | \__ \
|_| \__,_| \__,_| _/ | \__, | |___/
|__/ |___/
Enter the code depicted in ASCII art style.