Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Try doing it with that formatting - I'll be honest and say I'm not sure of the intricate differences but it should work.
Note the couple of extra bits in mine - the extra explamation mark and dollar sign. I know this is to do with regular expressions but not sure what difference they make without reading a reference book. Perhaps someone else on here can shed some light on that.