vim modelines

I can never remember what those comments that change vim settings are called, and spend hours trawling through vim’s help. They’re called modelines. :help modeline brings up the documentation.

Some typical modelines for copying and pasting:

Go

//
// vim: tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab tw=72
// run 'go fmt' before checking in your code!
//

Text files

# vim:tw=75
# vim:textwidth=75

Shell/Bash

# vim: ai ts=2 sw=2 et sts=2 ft=sh
# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=sh

Ruby

# vim: ai ts=2 sts=2 et sw=2 ft=ruby
# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=ruby

Python

# vim: ai ts=4 sts=4 et sw=4 ft=python
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python

Or when using vi (eg on Solaris) INVESTIGATE FURTHER:

:set sw=4

Perl

# vim: ai ts=4 sts=4 et sw=4 ft=perl
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=perl

LISP/Scheme

; vim: ft=lisp
Tags: , , , , , ,


Share This


 


2 Responses to vim modelines

  1. Very cool. Seem these at the top of some PEAR libraries. Couldn’t understand what they represented.

    I’ll be using this in Drupal as its standard indentation is 2 spaces where as most other PHP coding standards are four spaces.

    Cheers!

  2. [...] vim modelines | Sonia Hamilton – July 16th ( tags: vim modelines tips tricks programming configuration ) July 16th, 2012, @ 3:00 pm | Tags: links | Category: delicious links | Comments are closed | Trackback this Post | 0 views [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>