dummy Universitšt Bremen dummy dummy UFT Bremen
Johannes Ranke
VIM logo powered

vim R plugin for Linux/Unix

The old vim R plugin for Linux/Unix was inspired by a Lisp plugin for vim and was first published on www.vim.org in July 2004. The plugin works by starting R via a perl script in an xterm. This instance of R listenes for input both directly from the xterm as well as from a pipe that you can send code to from a vim instance.

Actually all the plugin does is to provide the perl script (funnel.pl) stemming from Larry Clapp's Lisp plugin and setting some mappings for starting such a listening R interpreter and sending code from the current vim buffer to R.

Please note that the plugin is not developed or maintained any more. I personally use, recommend and sometimes contribute to the cross-platform vim plugin and the R-Vim-runtime files maintained by Jakson Alves de Alquino

The following notes are kept on this page for historic purposes.


Here you can see my usual setup with two xterms:

On the left, an R script is edited. The R interpreter to the right was started by pressing <F2>. Some lines are visually selected for sending to the R interpreter to the right, simply by pressing the key "r". For looking at objects or trying out one-line commands, you can use the R console directly. This way, you end up mainly with working code in the R script to the left ...

Note that folded code can also comfortably be visually selected and sent over for execution.

I also include an ftplugin for Sweave (R noweb) files, where R syntax is mixed with Latex, as well as Makefile for comfortable processing with the vim command :make.

Installation and setup

Current Debian vim packages don't have filetype plugins enabled by default, so you have to enable them. You can do that sitewide by editing /etc/vim/vimrc (requires root privileges), or just for yourself by adding filetype plugin on to your ~/.vimrc file.

Otherwise, follow the instructions in the README included in the distribution on www.vim.org.


The plugin was developed on Linux. However, it should work on any platform supporting perl including the perl modules IO::Pty and Term::ReadLine. Term::ReadLine has to be the GNU version. Of course, you don't need to run vim in an xterm, you can also use a GUI version of vim, or run vim in a different terminal.

Xavier FernŠndez provided the following installation instructions for Gentoo Linux

** Install the 'IO-Tty' package (emerge IO-Tty)
** Install manually the GNU ReadLine library.

Remember that this one is not the one provided by gentoo as september 2006.
With 'dev-perl/Term-ReadLine-Perl' funnel.pl does not work. See:

+ Download it from

$ tar -xfz Term-ReadLine-Gnu-1.16.tar
$ cd Term-ReadLine-Gnu-1.16
Term-ReadLine-Gnu-1.16 $ perl Makefile.PL
Term-ReadLine-Gnu-1.16 $ make
Term-ReadLine-Gnu-1.16 $ sudo make install

** And for the rest proceed as indicated in the installation notes.

Michael Graber reported that funnel.pl does not run properly on Mac OS X. I think it should be possible to make it work, but I don't use this OS (yet?). Please drop me a note if you succeeded with this. Probably all you need to do is to install the GNU version of Term::ReadLine.

A workaround using Applescript was pointed out to me by Jarimatti Valkonen, and we actually started a cross-platform plugin. He uploaded his work to vim.org as Vim script Nr. 1741.

Another similar solution for Mac Os X is Vim script Nr. 2104.

Recently, Tony Makhlouf sent me his solution for Mac OS X:

The workaround uses Applescript, which is a standard way of  
interapplication communication on the Mac. The GUI R application has  
an Applescript command called "cmd" which takes a string argument and  
executes it in the main window of the GUI R application. So I created  
a couple of vim mappings and a small applescript file to bridge it over.

The mappings are :

:vmap   :w! ~/r.pipe !osascript ~/rcmd  
:nmap   :.w! ~/r.pipe !osascript ~/rcmd  

osascript is a utility that is part of the Mac OS X standard install  
that executes Applescripts.
 = pressing Apple-R [similar to m-r in Linux].
"rcmd" is a simple text file containing:

set f to POSIX file "/Users/username/r.pipe"
set c to (read f)
tell application "R"
  cmd c
end tell

IO::Pty is not included in the popular perl distrubution for Windows from ActiveState, but it is available in the cygwin environment. I never tried the latter approach. There are other solutions for connecting vim and R on Windows, such as the R vim suite by Jose Quesada, that uses a program called AutoHotKey, or the solution of Bill West, that uses the rcom library and the perl functionality of vim. I have an own solution based on the code of Bill West, that yanks the visual selection into the clipboard, and sends this to R, also using perl.

FranÁois Pinard posted some tips for vim-R integration on the r-help mailing list that should work cross-platform.

vim_R_linux.html last modified March 16, 2016