Vim R plugin

Jakson Alves de Aquino
José Cláudio Faria

 

This plugin improves Vim's support to edit R code.

Download the plugin:

    http://www.vim.org/scripts/script.php?script_id=2628

If you use Debian or a Debian based Linux distribution (Ubuntu or other), you may want to install the vim-r-plugin_0.9.9.9-1_all.deb package. After the installation, you can enable the plugin by doing the following commands:

   vim-addons remove r-plugin
   vim-addons install r-plugin


Notes:

  1. The Debian package of the plugin works with the Debian package of Vim. You have to adjust Vim's runtimepath if you have compiled Vim yourself and want to use vim-addon to install the plugin.
  2. The command "vim-addons remove r-plugin" is necessary only if there was a previous version of the plugin installed because new versions may include new files and, thus, there may be broken symbolic links.
  3. The Debian package doesn't work properly if your ~/.vim directory is a symbolic link. You should turn the ~/.vim directory in a real directory BEFORE using the vim-addon manager to install or uninstall the plugin.
  4. The color scheme used in most screenshots is here.

Please, read the plugin's documentation for details on usage.

 

Sample vimrc:

set nocompatible
syntax on
filetype plugin on
filetype indent on

"------------------------------------
" Behavior
"------------------------------------
let maplocalleader = ","
let mapleader = ";"

"------------------------------------
" Appearance
"------------------------------------
" www.vim.org/scripts/script.php?script_id=3292
colorscheme southernlights

"------------------------------------
" Search
"------------------------------------
set infercase
set hlsearch
set incsearch

"------------------------------------
" Showmarks
"------------------------------------
let marksCloseWhenSelected = 0
let showmarks_include="abcdefghijklmnopqrstuvwxyz"

"------------------------------------
" Vim-R-plugin
"------------------------------------
if has("win32") || has("win64") || $DISPLAY != ""
    let vimrplugin_openpdf = 1
    let vimrplugin_openhtml = 1
endif
if has("gui_running")
    inoremap <C-Space> <C-x><C-o>
else
    inoremap <Nul> <C-x><C-o>
endif
vmap <Space> <Plug>RDSendSelection
nmap <Space> <Plug>RDSendLine

 

Videos on youtube:

 

Screenshots:

 

The plugin running in a terminal emulator, using the screen.vim plugin and the Tmux application to split the terminal in two regions separated by a green line. Vim is running in one region and R in the other. We are using Vim's omni completion feature to complete "read.s". The scratch window at the top shows the arguments of read.spss(). The operating system is Linux:

 

The Vim window was split in two. At the right side the object browser shows the loaded libraries and we can see the objects of the library foreign.

 

Now, the the object browser shows the objects that are in R's workspace:


 

R documentation for the function attr() is shown in a separate tab:


 

Syntax highlight of R code. The output is being colorized by the R package colorout:


 

In this screenshot, we can also see the use of the ShowMarks plugin to highlight marks. In the example, we are repeatedly changing the legend's coordinates and sending the block of code between the marks 'a' and 'b' to find the best position of the legends:


 

The plugin on Windows. The option r_syntax_folding was set in the vimrc to enable folding by syntax and the function makeMap() is folded:


In the above picture, there are R related tool bar icons. To add them to the Vim-R-plugin, download the file bitmaps.zip and unpack it at either ~/.vim (Unix/Linux/Mac OS X) or ~/vimfiles (Windows).

 


Last change: Nov. 2013