Vim scans the first and last few lines of the file for modelines, if the modeline option is on (which it is, by default). If it finds any it will apply those settings as if you had typed them in manually using :set in command mode.
#!/bin/sh
# vim:ts=2:sw=2:expandtab
Übergibson: Embedding vim Settings in the File You’re Editing.