In a C file:

/*
  vim:sw=4:
*/

In a Perl file

# vim:expandtab
# vim:tabstop=4

In a JavaScript file

// vim:expandtab
// vim:tabstop=4

modline turns this feature on

modlines sets the number of lines to check

:set modline
:set modlines=10