tags:

views:

397

answers:

3

This I am sure is really basic stuff. I am just beginning using gvim and latex-suite. However I would like latex-suite to load when I edit a sweavefile with.Rnw extension.

my .vimrc looks like this

" These settings are needed for latex-suite
filetype indent on
filetype plugin on
filetype on
let g:tex_flavor='latex'
set grepprg=grep\ -nH\ $*
"let g:Tex_Folding=0 "I don't like folding.
set iskeyword+=:

and I guess there is some option I can set here that makes vim treat Rnw as .tex?

+2  A: 

Put a file in /usr/share/vim/vimfiles/ftdetect (for global) or .vim/ftdetect (for local) called Rnw.vim that looks something like this:

" Vim filetype detection plugin
" Language:    sweavefile

autocmd BufRead,BufNewFile *.Rnw set filetype=tex

Edit: I'm pretty sure you could put this autocommand in your .vimrc too, since that's loaded on program start, before any files are loaded, but this is directory the natural place for filetype detection.

Edit: If you would like to give these files some treatment different from TeX, you could instead set the filetype to rnw, add scripts to the ftplugin, indent, and syntax directories as necessary, most likely sourcing the TeX scripts and then doing your own stuff.

Jefromi
I put your suggestion in ftdetect (had to create it first). Now gvim opens .Rnw files in latex mode. Which is what I asked for. Thanks a lot!
Andreas
+2  A: 

Hope these pointers will help:

Shane
Cool. The filetype detection is essentially the same as what I suggested, but that will get you embedded syntax regions, which are pretty sweet. In order to get latex-suite to load as well, as I mention in my answer, you'll need to add an ftplugin for this filetype which does the same loading as you see in the TeX filetype plugin (in ftplugin, wherever latex-suite is installed).
Jefromi
Thank you Shane. Chip Campbell's post on the R-help list is a bit mysterious to me - as I dont know anything about syntax clusters in vim. But I guess I can just copy the file provided by Johannes Ranke.The feferraz post is very well written and I think, easy to follow. It seams feferraz and Ranke uses different approaches to achieve the same thing though? Is any one method better then the other?
Andreas
A: 

Hi, thanks for the pointers on this subject. I do have a question, however: I use both vim-r-plugin2 (by J. Aquino) and latex-suite. The above indications, I understand, help you get the syntax right for Rnw files. The vim-r-plugin2 already does that. However, my question is whether it is possible to make use of latex-suite for the latex chunks whilst still using the vim-r-plugin. Is there anything I need to change? It would be a shame to be writing relatively long, predominantly latex documents and not make use of latex-suite because of the occasional noweb chunk.

Thanks!

tc

typhooncamel