can't get syntax highlighting to work with R code in vim

linux, r, syntax-highlighting, vim

Solution

Try adding this line to the file `filetype.vim`. `filetype.vim` is generally located in the folder `~/.vim`. Create the file if it doesn't exist.

au! BufNewFile,BufRead *.R,*.Rout,*.r,*.Rhistory,*.Rt,*.Rout.save,*.Rout.fail setf r

On startup, vim links all the file extensions listed above to the filetype r, which is likely used by your syntax file. Your syntax file will not define the file extension for you typically.

See this reference for more information. For syntax highlighting, this tutorial might be helpful.

Problem

This is a naive (and likely dumb) question, but I can't seem to get the R syntax highlighting to work with my Linux setup. I've downloaded a `r.vim` file that has improved syntax highlighting, and it works on my Windows gvim setup. Does this `r.vim` file need to be in the `/usr/share/vim/v70/syntax` directory? Right now, I have it in my home directory and trying out `source ~/r.vim` in the `~/.vimrc` file. However, this doesn't seem to do anything. Perhaps I'm barking up the wrong tree?

Original source