For all those who think that Vim is The Editor for text files, and simultaneously think that R is The EnvironmentForStatisticalAnalysisAndGraphics.
After trying out various options for integrating Vim with R I settled on the following configuration:
- Use Vim-R-plugin for editing R code files, R documentation files (*.Rd) as well as the Sweave files. Apart from syntax highlighting the plugin allows to open an R console in a separate window and operate it with keyboard shortcuts from Vim (no need for frequent alt-tabbing etc.). Among other things you can:
- Execute individual code lines, visually selected portions, or whole R code files in the R console.
- Putting a cursor on a function name in the code file and: display its R help page, or display function arguments (through
- Put a cursor on any R object in the code file and perform frequently used functions:
- List the content of the R Workspace
- Clean the R Workspace
- I use Sweave quite extensively. For Sweave files the Vim-R-plugin provides the same keyboard mappings as for the R code files as well as nicely highlights both the LaTeX code and the R code in the code chunks. As my Sweave files have mostly LaTeX code with rather short R code snippets I would like to take advantage of another Vim plugin: the LaTeX-Suite. By default Vim will not load the Latex-suite for Sweave files, which is a HUGE disadvantage.
Here is a way how to use both plugins simultaneously for Sweave files. The instruction applies to Ubuntu (so probably any Linux-like system). On Windows the
~/.vim directory corresponds to the ‘vimfiles’ directory, which most likely is something like
c:\Program Files\Vim\vimfiles. So:
- Install Vim-R-plugin normally.
- Install Latex-suite normally.
~/.vim/ftpluginremove the symbolic link
rnoweb.vimand replace it with a normal text file with the following content:
runtime! ftplugin/r.vim runtime! ftplugin/tex_latexSuite.vim
This will essentially load both plugins one after another. QED.
See here how to set it up on Mac.