Sweave Syntax Highlighting in vim

If you use Sweave and vim, you might have wondered if it’s possible to have it syntax highlight Rnw/Snw files properly : the latex bits with LaTeX syntax and the noweb R chunks with R syntax. It is! Take a look a the screenshot below:

Screenshoot of a syntax-highlighted Sweave file

In order to have this working, you only need to properly configure your vim. First, edit your ~/.vim/filetype.vim, adding the following lines to it: