# vim-r-plugin ：：帮助文档的翻译和应用，帮助文档，常看常新，你遇到的问题，别人都想到了

vim 同时被 2 个专栏收录
15 篇文章 0 订阅
11 篇文章 0 订阅

1. Overview                                    |r-plugin-overview|
2. Main features                               |r-plugin-features|
3. Installation                                |r-plugin-installation|
4. Use                                         |r-plugin-use|
5. Known bugs and workarounds                  |r-plugin-known-bugs|
6. Options                                     |r-plugin-options|
7. Custom key bindings                         |r-plugin-key-bindings|
8. Files                                       |r-plugin-files|
9. FAQ and tips                                |r-plugin-tips|
10. News                                        |r-plugin-news|

==============================================================================
*r-plugin-overview*
1. 浏览

==============================================================================
*r-plugin-features*

2. 主要功能

*R代码的语法高亮，包括

- 某些特殊字符
- Functions of all installed packages (must be updated manually).
- Special highlighting for R output (.Rout files).
- Spell check only strings and comments.
- Fold code when foldmethod=syntax.
* 对一下内容也会高亮显示： RHelp, RMarkdown and RreStructuredText.
* 自动识别 for R, RHelp, Rnoweb, RMarkdown and RreStructuredText.
* 和R的通讯:

- 开启和关闭R

- 向R中发送行， selection, paragraphs, functions, blocks, entire file.
- Send commands with the object under cursor as argument: help, args,
plot, print, str, summary, example, names.
- Send to R the Sweave and pdflatex commands.
* Omni completion (auto-completion) for R objects (.GlobalEnv and installed
packages). The list of installed packages must be updated manually.
* Auto-completion of function arguments.
* Auto-completion of knitr chunk options.
* Ability to see R's documentation in a Vim's buffer:
- Automatic calculation of the best layout of the R documentation buffer
(split the window either horizontally or vertically according to the
available room).
- Automatic formating of the text to fit the panel width.
- Send code and commands to R (useful to run examples).
- Syntax highlighting of R documentation.
* Object Browser (.GlobalEnv and loaded packages):
- Send commands with the object under cursor as argument.
- Call R's help() with the object under cursor as argument.
- Syntax highlighting of the Object Browser.
* Most of the plugin's behavior is customizable.

For screenshots see: http://www.lepem.ufc.br/jaa/vim-r-plugin.html

==============================================================================
*r-plugin-installation*
3. 安装

The installation instructions are split in four sections: (1) general
instructions for all operating systems; (2) instructions that are specific for
either Unix/Linux/OSX or Windows; (3) troubleshooting; and (4) optional steps.

3.1. General instructions I~

Note: Most of the plugin commands require that you type the <LocalLeader>
which is '\' by default.

You need to activate plugins and indentation according to 'filetype'. You
should have at least the following options in your |vimrc|:
>
set nocompatible
syntax enable
filetype plugin on
filetype indent on
<
Make a backup of your ~/.vim directory because existing files will be
replaced. Please, look at |r-plugin-files| to see the list of files.

3.2. Operating system specific instructions~

3.2.1. Unix (Linux, OS X, etc.)~

Uncompress the archive:
>
unzip vim-r-plugin-*.zip -d ~/.vim
<
Start Vim and build the tags file for this document (and others that eventually
are in the same directory):
>
:helptags ~/.vim/doc
<
Note: If you are using Mac OS X and prefer that Vim uses AppleScript to send
commands to R, then the installation is finished and you should now read
sections 3.3 and 3.4.

In addition to having R installed in your system, this plugin has the
following dependencies:

Depends:~
Vim >= 7.3 with Python support.
Tmux >= 1.5:     http://tmux.sourceforge.net
Screen plugin:   http://www.vim.org/scripts/script.php?script_id=2711
vimcom = 0.9-5:  An R package.

Suggests:~
ncurses-term:  http://invisible-island.net/ncurses
colorout:      http://www.lepem.ufc.br/jaa/colorout.html
setwidth:      An R package.

Note: Tmux and ncurses-term are already packaged for most GNU/Linux
distributions and other Unix variants. The library ncurses-term is
necessary only for 256 color support in the terminal emulator.
Unfortunately their installation instructions vary widely and are beyond
the scope of this documentation.

The vimcom package creates a server on R to allow the communication with
Vim. The package is not used to send commands from Vim to R Console, but it
is necessary to open R documentation in Vim's buffer, run the Object
Browser, run either Sweave() or knit() on the document being edited. It
also has some functions called by Vim such as vim.plot(), vim.print(), and
vim.bol(). This last one is required to build the data base used in
omnicompletion. Before installing vimcom from source, you have to install
the X server development headers. On Debian/Ubuntu systems you can install
them with the following command in a terminal emulator:
>
sudo apt-get install libx11-dev
<
On Fedora/Red Hat, the command is:
>
sudo yum install libX11-devel
<
Finally, do in R:
>
install.packages("vimcom")
<
The colorout package colorizes the R output and the setwidth package
adjusts the value of options("width") whenever the terminal is resized.
They can be installed from within R.

The setwidth package can be installed as usual:
>
install.packages("setwidth")
<
You certainly will want to put something like the following at the end of
>
if(interactive()){
library(colorout)
library(setwidth)
library(vimcom)
}
<
The plugin will run R inside a Tmux session. If you are using Vim (not GVim),
you may be interested in reading |r-plugin-tmux| section to learn a few useful
shortcuts. The tmux.conf file created by the plugin sets Tmux to work with Vi
key bindings, <C-a> as the escape character and also enables the mouse for
Tmux.

Note: The plugin can use different mechanisms to send commands to R. The
mechanism that will be used depends on both what applications and plugins you
have installed and what options you have in your |vimrc|. The two lists below
show how the plugin will work on Linux in different conditions:

Vim                               Condition~
------------------------------    -------------------------------------
Screen plugin (Tmux)              default on Linux
Screen plugin (GNU Screen)        vimrplugin_tmux = 0
Tmux (external terminal)          vimrplugin_screenplugin = 0
GNU Screen (external terminal)    vimrplugin_screenplugin = 0 and
vimrplugin_tmux = 0

GVim                              Condition~
------------------------------    -------------------------------------
Tmux (external terminal)          default on Linux
GNU Screen (external terminal)    vimrplugin_tmux = 0

Note: On Mac OS X the plugin will use AppleScript in both Vim and GVim unless
vimrplugin_applescript = 0.

## 这里是window下的安装和应用，在前面一篇文章里差不多都讲过了

* Vim's version must be >= 7.3，vim的版本必须>=7.3

needs a specific version of Python DLL. For example, the official
Vim 7.3 for Windows needs either Python 2.7 or 3.1. If Python was
information about what Python version Vim was compiled against. Do
the following if you want to discover this information manually:

1. Type  :version  in Vim (normal mode).

2. Look for a string like -DDYNAMIC_PYTHON_DLL="python27.dll".

3. Install the Python version which corresponds to the version
which Vim was linked against. In the example of step 2
(python27.dll) the required Python version is 2.7.x.

* pywin32: http://sourceforge.net/projects/pywin32/

Note: The default download may not match the Python version Vim was
find the file that matches exactly the version of Python that you
installed.

* vimcom = 0.9-5: An R package, available on CRAN and installable with the
install.packages() command. The vimcom package creates a server on R to
allow the communication with Vim. You certainly will want to put the
following lines at the end of your Rprofile (usually at
~/Documents/.Rprofile):
>
if(interactive()){
library(vimcom)
}
<
Create your |vimfiles| directory if you do not have it yet. Its path will be
similar to one of the following:
>
<
Uncompress the archive. Right click on the plugin's zip file and choose
"Extract all". Then choose ~/vimfiles as the destination directory.

Start Vim and build the tags file for this document (and others that eventually
are in the same directory):
>
:helptags ~\vimfiles\doc
<
Start editing an R file with GVim and try to send some lines to R Console. You
may have to adjust the value of |vimrplugin_sleeptime|.

3.3. Troubleshooting (if the plugin doesn't work)~

Note: The <LocalLeader> is '\' by default.

The plugin is a |file-type| plugin. It will be active only if you are editing
a .R or .Rnw file. The menu items and tool bar buttons will not be visible and
the key bindings will not be active while editing either unnamed files or
files with name extensions other than .R or .Rnw. If the plugin is active,

Look at the ~/.vim (Linux, Unix, OS X) or ~/vimfiles (Windows) directory. Is
there a subdirectory named "r-plugin"? If not, then you unpacked the plugin in
the wrong place.

Did you see warning messages but they disappeared before you have had time to
read them? Type the command |:messages| in Normal mode to see them again.

Are you using Debian, Ubuntu or other Debian based Linux distribution? If yes,
you may prefer to install the Debian package available at:

http://www.lepem.ufc.br/jaa/vim-r-plugin.html

Did you see the message "VimCom port not found"? This means that R is not
running, the vimcom package is not installed, or R was not started by Vim.

3.4. General instructions II (optional steps)~

3.4.1 Update list of objects~

Start R and update the list of objects for omni completion and syntax
highlight (see |:RUpdateObjList| for details).

3.4.2 Customize the plugin~

section Indenting setup (|r-plugin-indenting|) of this document.

3.4.3 Hide unused buttons~

Edit GVim's toolbar and remove the buttons that you never use. The plugin adds
some buttons to the toolbar, but you may not see them because GVim has too
many buttons by default. Please see the page below to know how to hide buttons
on the toolbar:

You may be interested in installing additional general plugins to get
functionality not provided by this file type plugin. ShowMarks and snipMate
edit Rnoweb files, you may want to try LaTeX-Box for omnicompletion of LaTeX
code.

==============================================================================
*r-plugin-use*
4. Use~

4.1. Key bindings~

Note: The <LocalLeader> is '\' by default.

Note: It is recommended the use of different keys for <Leader> and
<LocalLeader> to avoid clashes between filetype plugins and general plugins
key binds. See |filetype-plugins| and |maplocalleader|.

To use the plugin, open a .R or .Rnw or .Rd file with Vim and type
<LocalLeader>rf. Then, you will be able to use the plugin key bindings to send
commands to R.

This plugin has many key bindings, which correspond with menu entries and, in
some cases, toolbar buttons. In the list below, the backslash represents the
enabled in all filetypes supported by the plugin (r, rnoweb, rhelp):

## 快捷键

Start/Close
. Start R (default)                                  \rf
. Start R --vanilla                                  \rv
. Start R (custom)                                   \rc
--------------------------------------------------------
. Close R (no save)                                  \rq
-----------------------------------------------------------

Send
. File                                               \aa
. File (echo)                                        \ae
. File (open .Rout)                                  \ao
--------------------------------------------------------
. Block (cur)                                        \bb
. Block (cur, echo)                                  \be
. Block (cur, down)                                  \bd
. Block (cur, echo and down)                         \ba
--------------------------------------------------------
. Chunk (cur)                                        \cc
. Chunk (cur, echo)                                  \ce
. Chunk (cur, down)                                  \cd
. Chunk (cur, echo and down)                         \ca
--------------------------------------------------------
. Function (cur)                                     \ff
. Function (cur, echo)                               \fe
. Function (cur and down)                            \fd
. Function (cur, echo and down)                      \fa
--------------------------------------------------------
. Selection                                          \ss
. Selection (echo)                                   \se
. Selection (and down)                               \sd
. Selection (echo and down)                          \sa
--------------------------------------------------------
. Paragraph                                          \pp
. Paragraph (echo)                                   \pe
. Paragraph (and down)                               \pd
. Paragraph (echo and down)                          \pa
--------------------------------------------------------
. Line                                                \l
. Line (and down)                                     \d
. Line (and new one)                                  \q
. Left part of line (cur)                       \r<Left>
. Right part of line (cur)                     \r<Right>
-----------------------------------------------------------

Command
. List space                                         \rl
. Clear console                                      \rr
. Clear all                                          \rm
--------------------------------------------------------
. Print (cur)                                        \rp
. Names (cur)                                        \rn
. Structure (cur)                                    \rt
--------------------------------------------------------
. Arguments (cur)                                    \ra
. Example (cur)                                      \re
. Help (cur)                                         \rh
--------------------------------------------------------
. Summary (cur)                                      \rs
. Plot (cur)                                         \rg
. Plot and summary (cur)                             \rb
--------------------------------------------------------
. Set working directory (cur file path)              \rd
--------------------------------------------------------
. Sweave (cur file)                                  \sw
. Sweave and PDF (cur file)                          \sp
. Sweave and PDF (cur file, verbose) (Windows)       \sv
. Sweave, BibTeX and PDF (cur file) (Linux/Unix)     \sb
--------------------------------------------------------
. Knit (cur file)                                    \kn
. Spin (cur file)                                    \ks
. Knit and PDF (cur file)                            \kp
. Knit and Beamer PDF (cur file) (Only Rmd)          \kl
. Knit and PDF (cur file, verbose) (Windows)         \kv
. Knit, BibTeX and PDF (cur file) (Linux/Unix)       \kb
--------------------------------------------------------
. Open PDF (cur file)                                \op
--------------------------------------------------------
. Build tags file (cur dir)                  :RBuildTags
-----------------------------------------------------------

Edit
. Insert "<-"                                          _
. Complete object name                              ^X^O
. Complete function arguments                       ^X^A
--------------------------------------------------------
. Indent (line)                                       ==
. Indent (selected lines)                              =
. Indent (whole buffer)                             gg=G
--------------------------------------------------------
. Comment/Uncomment (line, sel)                      \xx
. Add/Align right comment (line, sel)                 \;
--------------------------------------------------------
. Go (next R chunk)                                   gn
. Go (previous R chunk)                               gN
-----------------------------------------------------------

Syntax
. Build omnils (loaded packages)       :RUpdateObjList
-----------------------------------------------------------

Object Browser
. Show/Update                                        \ro
. Expand (all lists)                                 \r=
. Collapse (all lists)                               \r-
. Toggle (cur)                                     Enter
-----------------------------------------------------------

Help (plugin)
Help (R)                                            :Rhelp
-----------------------------------------------------------

Please see |r-plugin-key-bindings| to learn how to customize the key bindings
without editing the plugin directly.

The plugin commands that send code to R Console are the most commonly used. If
the code to be sent to R has a single line it is sent directly to R Console,
but if it has more than one line (a selection of lines, a block of lines
between two marks, a paragraph etc) the lines are written to a file and the
plugin sends to R the command to source the file. For example, when sending a

After the command <LocalLeader>ao, Vim will save the current buffer if it has
any pending changes, run "R CMD BATCH --no-restore --no-save" on the current
file and show the resulting .Rout file in a new tab. Please see
|vimrplugin_routnotab| if you prefer that the file is open in a new split
window. Note: The command <LocalLeader>ao, silently writes the current buffer
to its file if it was modified and deletes the .Rout file if it exists.

## vim-r-plugin中怎么输入下划线：连着输入两次下划线就出来了

R syntax uses " <- " to assign values to variables which is inconvenient to
type. In insert mode, typing a single underscore, "_", will write " <- ",
unless you are typing inside a string. The replacement will always happen if
syntax highlighting is off (see |:syn-on| and |:syn-off|). If necessary, it is
possible to insert an actual underscore into your file by typing a second
underscore. This behavior is similar to the EMACS ESS mode some users may be
familiar with and is enabled by default. You have to change the value of
|vimrplugin_assign| to disable underscore replacement.

When you press <LocalLeader>rh, the plugin shows the help for the function
under the cursor. The plugin also checks the class of the object passed as
argument to the function to try to figure out whether the function is a
generic one and whether it is more appropriate to show a specific method. The
same procedure is followed with <LocalLeader>rp, that is, while printing an
object. For example, if you run the code below and, then, press
plugin will show different documentations and print different objects in each
case:
>
y <- rnorm(100)
x <- rnorm(100)
m <- lm(y ~ x)
summary(x)
summary(m)
<
When completing object names (CTRL-X CTRL-O) and function arguments (CTRL-X
CTRL-A) you have to press CTRL-N to go foward in the list and CTRL-P to go
backward (see |popupmenu-completion|). Note: if using Vim in a terminal
emulator, Tmux will capture the CTRL-A command. You have to do CTRL-A twice to
pass a single CTRL-A to Vim. For rnoweb, rmd and rrst file types, CTRL-X
CTRL-A can also be used to complete knitr chunk options if the cursor is

If R is not running or if it is running but is busy the completion will be
based on information saved with the command |:RUpdateObjList|. Otherwise, the
pop up menu for completion of function arguments will include an additional
line with the name of the library where the function is (if the function name
can be found in more than one library) and the function method (if what is
being shown are the arguments of a method and not of the function itself).

To get help on an R topic, type in Vim (Normal mode):
>
:Rhelp topic
<
The command may be abbreviated to  :Rh  and you can either press <Tab> to
trigger the autocompletion of R objects names or hit CTRL-D to list the
possible completions (see |cmdline-completion| for details on the various ways
of getting command-line completion). The list of objects used for
completion is the same one built by |:RUpdateObjList|.

You can source all .R files in a directory with the Normal mode command
:RSourceDir, which accepts an optional argument (the directory to be sourced).

The command  :Rinsert <cmd>  inserts one or more lines with the output of the
R command sent to R. By using this command we can avoid the need of copying
and pasting the output R from its console to Vim. For example, to insert the
output of "dput(levels(var))", where "var" is a factor vector, we could do in
Vim:
>
:Rinsert dput(levels(var))
<
The output inserted by  :Rinsert  is limited to 5012 characters.

The command  :Rformat  call the function tidy.source() of formatR package to
format either the entire buffer or the selected lines. The value of the
"width.cutoff" argument is set to the buffer's 'textwidth' if it is not
outside the range 20-180. Se R help on "tidy.source" for details on how to
control the function behavior.

4.2. Edition of rnoweb files~

In Rnoweb files (.Rnw), when the cursor is over the "@" character, which
finishes an R chunk, the sending of all commands to R is suspended and the
shortcut to send the current line makes the cursor to jump to the next chunk.
While editing rnoweb files, the following commands are available in Normal
mode:

[count]gn : go to the next chunk of R code
[count]gN : go to the previous chunk of R code

4.3. Omni completion and the highlighting of functions~
*:RUpdateObjList*
The plugin adds some features to the default syntax highlight of R code. One
such feature is the highlight of R functions. However, only functions that
R loads by default are highlighted. To add functions of other libraries, you
should do the following:

1. Start R from within Vim.
2. Use R's library() to load the libraries whose functions you want
highlighted.
3. Run the following command in Vim's Normal mode:
:RUpdateObjList

The command :RUpdateObjList in addition to creating a list of function names
to be highlighted also creates a file containing a list of objects for omni
completion (|compl-omni|) including all objects currently in R's workspace,
except the .GlobalEnv objects. These two lists are stored permanently in the
~/.vim/r-plugin directory.

The command  :RUpdateObjList  waits 60 seconds to R finish building the list.
If this time is not enough to your system, please, set a different value of
|vimrplugin_buildwait|.

You should run  :RUpdateObjList  whenever you upgrade R since some functions
are removed and new ones are added at each new R version.

If have already run  :RUpdateObjList  and now want to add the objects of
specific libraries to both the list of objects for omnicompletion and the list
of functions for syntax highlight you can use the Vim command  :RAddLibToList.
Example:
>
<
Note: If you have too many loaded packages Vim may be unable to load the list
of functions for syntax highlight. If you want to remove the objects of
specific libraries, please, delete the corresponding files from
~/.vim/r-plugin/objlist/ directory (the directory may be at a different
location if you are using a plugin management system like vim-addons or
pathogen).

4.4. Omni completion~

Vim can automatically complete the names of R objects when CTRL-X CTRL-O is
pressed in insert mode (see |omni-completion| for details and 'completeopt' to
know how to customize the |omni-completion|). Omni completion shows in a pop
up menu the name of the object, its class and its environment (most
frequently, its package name). If the object is a function, its arguments are
shown in a separate window.

If a data.frame is found, while building the list of objects, the columns in
the data.frame are added to the list. When you try to use omni completion to
complete the name of a data.frame, the columns are not shown. But when the
data.frame name is already complete, and you have inserted the '' symbol, omni completion will show the column names. Vim uses one for the objects of .GlobalEnv and a list of files for all other objects. The .GlobalEnv list is stored in the /tmp/r-plugin-yourlogin directory and, thus, is deleted after each reboot. The other files are stored in ~/.vim/r-plugin/objlist/ and remain available until you manually delete them. 4.5. The Object Browser~ You have to do <LocalLeader>ro to either start or updated the Object Browser. The updating is automatic only if the Object Browser is running in a separate Tmux panel. The Object Browser has two views: .GlobalEnv and Libraries. If you either press <Enter> or double click (GVim or Vim with 'mouse' set to "a") on the first line of the Object Browser it will toggle the view between the objects in .GlobalEnv and the currently loaded libraries. The Object Browser requires the |+clientserver| feature to be automatically updated and the |+conceal| feature to correctly align list items. Note: On Linux you may find binaries without the |clientserver| feature if you install packages such as vim-nox on Debian/Ubuntu or vim-enhanced on Fedora/Red Hat. If you want to use Vim in a terminal emulator in Fedora/Red Hat, you may want to create a symbolic link to "gvim" named "vim". In the .GlobalEnv view, if an object has the attribute "label", it will also be displayed. Please, see the R help for package vimcom for some options to control the Object Browser behavior. In the Object Browser window, while in Normal mode, you can either press <Enter> or double click (GVim only) over a data.frame or list to show/hide its elements (not if viewing the content of loaded libraries). If you are running R in an environment where the string UTF-8 is part of either LC_MESSAGES or LC_ALL variables, unicode line drawing characters will be used to draw lines in the Object Browser. This is the case of most Linux distributions. In the Libraries view, you can either double click or press <Enter> over a library to see its objects. In the Object Browser, the libraries have the color defined by the PreProc highlighting group, and the other objects have their colors defined by the return value of some R functions. Each line in the table below shows a highlighting group and the corresponding R function (if any) used to classify the objects: PreProc libraries Number is.numeric() String is.character() Special is.factor() Boolean is.logical() Type is.list() Function is.function() Statement isS4() One limitation is that objects made available by the command data() may not have their classes recognized in the GlobalEnv view. The Normal mode command d deletes the object on the cursor line or the element of a list or data.frame. If the Object Browser is showing the libraries, the library currently under the cursor line is detached. 4.6. Commenting and uncommenting lines~ You can toggle the state of a line as either commented or uncommented by typing <LocalLeader>xx. You can also add comments to the right of a line with the <LocalLeader>; shortcut. By default, the comment starts at the 40th column, which can be changed by setting the value of r_indent_comment_column, as below: > let r_indent_comment_column = 20 < If the line is longer than 38 characters, the comment will start two columns after the last character in the line. If you are running <LocalLeader>; over a selection of lines, the comments will be aligned according to the longest line. While typing comments the leader comment string is automatically added to new lines when you reach 'textwidth' but not when you press <Enter>. Please, read the Vim help about 'formatoptions' and |fo-table|. For example, you can add the following line to your |vimrc| if you want the comment string being added after <Enter>: > autocmd FileType r setlocal formatoptions-=t formatoptions+=croql < 4.7. Build a tags file to jump to function definitions~ *:RBuildTags* Vim can jump to functions defined in other files if you press CTRL-] over the name of a function, but it needs a tags file to be able to find the function definition (see |tags-and-searches|). The command :RBuildTags calls the R function rtags() to build the tags file for the R scripts in the current directory. Please read |r-plugin-tagsfile| to learn how to create a tags file referencing source code located in other directories, including the entire R source code. 4.8. Tmux usage~ *r-plugin-tmux* When running Vim in a terminal emulator (Linux/Unix only), the Vim-R-plugin will use the screen.vim plugin to restart Vim and start R in a Tmux session. The Tmux configuration file provided by the Vim-R-plugin configures Tmux to use vi key bindings. It also configures Tmux to react to mouse clicks. You should be able to switch the active pane by clicking on an inactive pane, to resize the panes by clicking on the border line and dragging it, and to scroll the R Console with the mouse wheel. When you use the mouse wheel, Tmux enters in its copy/scroll back mode (see below). The configuration script also sets <C-a> as the Tmux scape character (the default is <C-b>), that is, you have to type <C-a> before typing a Tmux command. Below are the most useful key bindings to use Tmux with the tmux.conf created by the Vim-R-plugin (see |vimrplugin_notmuxconf| if you prefer to use your own ~/.tmux.conf) <C-a>arrow keys : Move the cursor to the Tmux panel above, below, at the right or at the left of the current one. <C-a><C-Up> : Move the panel division upward one line, that is, resize the panels. Repeat <C-Up> to move more. <C-Down> will move the division downward one line. If you are using the vertical split, you should use <C-Left> and <C-Right> to resize the panels. <C-a>[ : Enter the copy/scroll back mode. You can use <PgUp>, <PgDown> and vi key bindings to move the cursor around the panel. Press q to quit copy mode. <C-a>] : Paste the content of Tmux paste buffer. While in the copy and scroll back mode, the following key bindings are very useful: q : Quit the copy and scroll mode. <Space> : Start text selection. v<Space> : Start rectangular text selection. <Enter> : Copy the selection to Tmux paste buffer. Please, read the manual page of Tmux if you want to change the Tmux configuration and learn more commands. To read the Tmux manual, type in the terminal emulator: > man tmux > Note: <C-a> was configured as the Tmux scape character, and it will not be passed to applications running under Tmux. To send <C-a> to either R or Vim you have to type <C-a>a. With Tmux, you can the detach the Vim-R session and reattach it latter. This is useful if you plan to begin the use the Vim-R-plugin in a machine and latter move to another computer. However, normally you will get |E325|, caused by the presence of a 'swapfile' (please, read the screen.vim plugin documentation, especially the section |screen-gotchas| for details). This problem will not happen if you start Vim from within a Tmux session, as in the example below. A sample detachable session could be: - Create your ~/.tmux.conf if it does not exist yet. You may put the lines below in your ~/.tmux.conf as a starting point to your own configuration file: > set-option -g prefix C-a unbind-key C-b bind-key C-a send-prefix set-window-option -g mode-keys vi set -g terminal-overrides 'xterm*:smcup@:rmcup@' set -g mode-mouse on set -g mouse-select-pane on set -g mouse-resize-pane on < - Start Tmux: tmux - Start Vim: vim theScript.R - Use Vim to start an R session: <LocalLeader>rf - Send code from Vim to R, and, then, detach Vim and R with <C-a>d The command will be <C-b>d if you have not set <C-a> as the scape character in your ~/.tmux.conf. - Some time latter (even if accessing the machine remotely) reattach the Tmux session: tmux attach See |vimrplugin_only_in_tmux| if you always prefer starting Tmux before starting Vim, but sometimes forget to start Tmux. 4.9. GNU Screen usage~ *r-plugin-screen* When running Vim in a terminal emulator (Linux/Unix only), the Vim-R-plugin will use the screen.vim plugin to restart Vim and start R in a Tmux session. However, the plugin will use GNU Screen if Tmux is not installed or if you have set the value of vimrplugin_tmux = 0 in your |vimrc|. You may want to create your own ~/.screenrc to customize GNU Screen behavior (see |vimrplugin_noscreenrc|). Below are the most useful key bindings to use the Vim-R-plugin with the screenrc that the plugin creates: <C-Tab> : Move the cursor to the next panel. <C-a>a : Decrease the height of the current panel. <C-a>z : Increase the height of the current panel. <C-a>[ : Enter the copy/scroll back mode. You can use <PgUp>, <PgDown> and vi key bindings to move the cursor around the panel. Press q to quit copy mode. <C-a>] : Paste the content of GNU Screen paste buffer. While in the copy and scroll back mode, the following key bindings are very useful: q : Quit the copy and scroll mode. <Space> : Start text selection. <Enter> : Copy the selection to GNU Screen paste buffer. ============================================================================== *r-plugin-known-bugs* 5. Known bugs and workarounds~ The bugs that are known to exist but that will not be fixed are listed in this section. Some of them can not be fixed because they depend on either R or Vim missing features; others would be very time consuming to fix without breaking anything. 5.1. R's source() issues~ The R's source() function prints an extra new line between commands if the option echo = TRUE, and error messages and warning are printed only after the entire code is sourced, which makes it more difficult to find errors in the code sent to R. Details: https://stat.ethz.ch/pipermail/r-devel/2012-December/065352.html 5.2. The clipboard's content is lost (Windows only)~ On Windows, the plugin copies the command that will be sent to R into the clipboard. Thus, if you have anything in the clipboard it will be lost while using the plugin. 5.3. The menu may not reflect some of your custom key bindings~ If you have created a custom key binding for the Vim-R-plugin, the menu in GVim will not always reflect the correct key binding if it is not the same for Normal, Visual and Insert modes. 5.4. Syntactically correct code may be wrongly indented~ If the Vim-R-plugin indents your code wrongly you may get the correct indentation by adding braces and line breaks to it. For example, try to indent the code below: > # This code will be wrongly indented: levels(x) <- ## nl == nL or 1 if (nl == nL) as.character(labels) else paste(labels, seq_along(levels), sep = "") class(x) <- c(if(ordered) "ordered", "factor") # But this one will be correctly indented: levels(x) <- ## nl == nL or 1 if (nl == nL) as.character(labels) else paste(labels, seq_along(levels), sep = "") class(x) <- c(if(ordered) "ordered", "factor") < 5.5. Wrong message that "R is busy"~ When code is sent from Vim to R Console, the vimcom library sets the value of the internal variable "r_is_busy" to 1. The value is set back to 0 when any code is successfully evaluated. If you send invalid code to R, there will be no successful evaluation of code and, thus, the value of "r_is_busy" will remain set to 1. Then, if you try to update the object browser, see the R documentation for any function, or do other tasks that require the hidden evaluation of code by R, the vimcom library will refuse to do the tasks to avoid any risk of corrupting R's memory. It will tell Vim that "R is busy" and Vim will display this message. Everything should work as expected again after any valid code is executed in R Console. 5.6. Commands are sent twice on Mac OS X~ If you use the screen plugin with GNU Screen, individual lines may be sent duplicated to R on Mac OS X. ============================================================================== *r-plugin-options* 6. Options~ |vimrplugin_term| External terminal to be used |vimrplugin_term_cmd| Complete command to open an external terminal |vimrplugin_assign| Convert '_' into ' <- ' |vimrplugin_assign_map| Choose what to convert into ' <- ' |vimrplugin_rnowebchunk| Convert '<' into '<<>>=\n@' in Rnoweb files |vimrplugin_objbr_place| Placement of Object Browser |vimrplugin_objbr_w| Initial width of Object Browser window |vimrplugin_external_ob| Run Object Browser on external terminal |vimrplugin_vimpager| Use Vim to see R documentation |vimrplugin_editor_w| Minimum width of R script buffer |vimrplugin_help_w| Desired width of R documentation buffer |vimrplugin_nosingler| A single R process for all Vim instances |vimrplugin_by_vim_instance| Each Vim instance runs its own R |vimrplugin_i386| Use 32 bit version of R |vimrplugin_r_path| Directory where R is |vimrplugin_r_args| Arguments to pass to R |vimrplugin_buildwait| Time to wait for :RUpdateObjList to finish |vimrplugin_routmorecolors| More syntax highlighting in R output |vimrplugin_routnotab| Show output of R CMD BATCH in new window |vimrplugin_indent_commented| Indent lines commented with the \xx command |vimrplugin_sleeptime| Delay while sending commands in MS Windows |vimrplugin_noscreenrc| Do not write custom screenrc |vimrplugin_screenplugin| Use the screen.vim plugin |vimrplugin_screenvsplit| Split the window vertically (screen plugin) |vimrplugin_tmux| Choose between Tmux and GNU Screen |vimrplugin_applescript| Use osascript in Mac OS X. |vimrplugin_listmethods| Do .vim.list.args() instead of args() |vimrplugin_specialplot| Do .vim.plot() instead of plot() |vimrplugin_maxdeparse| Argument to R args() function |vimrplugin_latexcmd| Command to run on .tex files |vimrplugin_sweaveargs| Arguments do Sweave() |vimrplugin_never_unmake_menu| Do not unmake the menu when switching buffers |vimrplugin_map_r| Use 'r' to send lines and selected text |vimrplugin_ca_ck| Add ^A^K to the beginning of commands. |vimrplugin_openpdf| Open PDF after processing rnoweb file. |vimrplugin_openpdf_quietly| Open PDF quietly. |vimrplugin_openhtml| Open PDF quietly. |vimrplugin_strict_rst| Code style for generated rst files. |vimrplugin_insert_mode_cmds| Allow R commands in insert mode. |vimrplugin_allnames| Show names which begin with a dot |vimrplugin_rmhidden| Remove hidden objects from R workspace. 6.1. Terminal emulator (Linux/Unix only)~ *vimrplugin_term* The plugin uses the first terminal emulator that it finds in the following list: 1. gnome-terminal, 2. konsole, 3. xfce4-terminal, 4. iterm 5. Eterm, 6. rxvt, 7. aterm, 8. roxterm, 9. terminator, 10. xterm. If Vim does not select your favorite terminal emulator, you may define it in your |vimrc| by setting the variable vimrplugin_term, as shown below: > let vimrplugin_term = "xterm" let vimrplugin_term = "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal" < *vimrplugin_term_cmd* If your terminal emulator is not listed above, or if you are not satisfied with the way your terminal emulator is called by the plugin, you may define in your |vimrc| the variable vimrplugin_term_cmd, as in the examples below: > let vimrplugin_term_cmd = "gnome-terminal --title R -e" let vimrplugin_term_cmd = "terminator --title R -x" let vimrplugin_term_cmd = "/Applications/Utilities/iTerm.app/Contents/MacOS/iTerm -t R" < Please, look at the manual of your terminal emulator to know how to call it. The last argument must be the one which precedes the command to be executed. 6.2. Assignment operator and Rnoweb completion of code block~ *vimrplugin_assign* *vimrplugin_assign_map* *vimrplugin_rnowebchunk* While editing R code, '_' is replaced with ' <- '. To disable this feature, put in your |vimrc|: > let vimrplugin_assign = 0 < If want to bind other keys to be replaced by ' <- ', set the value of |vimrplugin_assign_map| in your |vimrc|, as in the example below which emulates RStudio behavior (may only works on GVim): > let vimrplugin_assign_map = "<M-->" < Note: You can't map <C-=>, as StatET does. In Rnoweb files, a '<' is replaced with '<<>>=\n@'. To disable this feature, put in your |vimrc|: > let vimrplugin_rnowebchunk = 0 < 6.3. Object Browser options~ *vimrplugin_objbr_place* *vimrplugin_objbr_w* *vimrplugin_external_ob* By default, the object browser will be created with 40 columns. The minimum width of the Object Browser window is 9 columns. You can change the object browser's default width by setting the value of |vimrplugin_objbr_w| in your |vimrc|, as below: > let vimrplugin_objbr_w = 30 < The Object Browser will always be created by splitting the Vim script window if you are running GVim. However, if running Vim in a terminal emulator, the Object Browser will be created in a independent Vim instance in a Tmux panel beside the R Console. Valid values for the Object Browser placement are "script" or "console" and "right" or "left" separated by a comma. Examples: > let vimrplugin_objbr_place = "script,right" let vimrplugin_objbr_place = "console,left" < If vimrplugin_external_ob = 1 and R is running in an external terminal emulator and the communication with R is being established through Tmux, the Object Browser will be placed besides the R Console in the external terminal emulator. In this case, the command <LocalLeader>rh will not work on the Object Browser (you will see the message "Cmd not available"). 6.4. Vim as pager for R help~ *vimrplugin_vimpager* *vimrplugin_editor_w* *vimrplugin_help_w* 6.4.1. Quick setup~ If you do not want to see R documentation in a Vim's buffer, put in your |vimrc|: > let vimrplugin_vimpager = "no" < If you want to use Vim to see R documentation even when looking for help in the R console, put in your .Rprofile: > options(pager = "vim -c 'set ft=rdoc' -") < 6.4.2. Details and other options:~ The plugin key bindings will remain active in the documentation buffer, and, thus, you will be able to send commands to R as you do while editing an R script. You can, for example, use <LocalLeader>rh to jump to another R help document. The valid values of vimrplugin_vimpager are: "tab" : Show the help document in a new tab. If there is already a tab with an R help document, use it. This is the default. "vertical" : Split the window vertically if the editor width is large enough; otherwise, split the window horizontally and attempt to set the window height to at least 20 lines. "horizontal": Split the window horizontally. "tabnew" : Show the help document in a new tab. "no" : Do not show R documentation in Vim. The window will be considered large enough if it has more columns than vimrplugin_editor_w + vimrplugin_help_w. These variables control the minimum width of the editor window and the help window, and their default values are, respectively, 66 and 46. Thus, if you want to have more control over Vim's behavior while opening R's documentations, you will want to set different values to some variables in your |vimrc|, as in the example: > let vimrplugin_editor_w = 80 let vimrplugin_editor_h = 60 < 6.5. Number of R processes (Linux/Unix only)~ *vimrplugin_nosingler* *vimrplugin_by_vim_instance* 6.5.1 Using (G)Vim without the screen.vim plugin~ By default, all buffers of all (G)Vim instances send code to the same R process. If you prefer that each Vim buffer uses its own R process, put the following option in your |vimrc|: > let vimrplugin_nosingler = 1 < If you prefer that each Vim instance calls its own R process and all the instance's buffers send code to this R process while other Vim instances send code to other R processes then put the following in your |vimrc|: > let vimrplugin_by_vim_instance = 1 > The |vimrplugin_by_vim_instance| option requires that Vim is acting as a command server because the variable |v:servername| is used to make the name of the Tmux session which will run R. By default, GVim runs as server, but Vim does not. Hence, if you are using Vim you have either to start Vim with the argument --servername or use the screen.vim plugin which tries to restart Vim with the --servername argument. If you want to use more than nine GVim instances you will have to use the --servername argument because screen will not differentiate between names like "GVIM1" and "GVIM10". 6.5.2 Using the screen.vim plugin~ Both options are ignored when using Vim in a terminal emulator and using the screen.vim plugin. The plugin behaves as if the |vimrplugin_by_instance| was enabled. 6.6. Use 32 bit version of R (Windows and Mac OS X only)~ *vimrplugin_i386* If you are using a 64 bit Windows or a 64 bit Mac OS X, but prefer to run the 32 bit version of R, put in your |vimrc|: > let vimrplugin_i386 = 1 < 6.7. R path~ *vimrplugin_r_path* Vim will run the first R executable in the path. You can set an alternative R path in your |vimrc| as in the examples: > let vimrplugin_r_path = "/path/to/my/preferred/R/version/bin" let vimrplugin_r_path = "C:\\Program Files\\R\\R-2.15.1\\bin\\i386" > On Windows, Vim will try to find the R install path in the Windows Registry. 6.8. Arguments to R~ *vimrplugin_r_args* Set this option in your |vimrc| if you want to pass command line arguments to R at the startup. Example: > let vimrplugin_r_args = "--sdi --no-save --quiet" < On Linux, there is no default value for |vimrplugin_r_args|. On Windows, the default value is "--sdi", but you may change it to "--mdi" if you do not like the SDI style of the graphical user interface. 6.9. Time necessary to build list of objects for omni completion~ *vimrplugin_buildwait* If your system needs more than 60 seconds to build the list of objects for omni completion after you do the command |:RUpdateObjList|, then you should set the value of |vimrplugin_buildwait| to a higher value. Example: > let vimrplugin_buildwait = 240 > 6.10. More colorful syntax highlight of .Rout files~ *vimrplugin_routmorecolors* By default, the R commands in .Rout files are highlighted with the color of comments, and only the output of commands has some of its elements highlighted (numbers, strings, index of vectors, warnings and errors). If you prefer that R commands in the R output are highlighted as they are in R scripts, put the following in your |vimrc|: > let vimrplugin_routmorecolors = 1 < 6.11. How to automatically open the .Rout file~ *vimrplugin_routnotab* After the command <LocalLeader>ao, Vim will save the current buffer if it has any pending changes, run "R CMD BATCH --no-restore --no-save" on the current file and show the resulting .Rout file in a new tab. If you prefer that the file is open in a new split window, put in your |vimrc|: > let vimrplugin_routnotab = 1 < 6.12. Indent commented lines~ *vimrplugin_indent_commented* You can type <LocalLeader>xx to comment out a line or selected lines. If the line already starts with a comment string, it will be removed. After adding the comment string, the line will be reindented by default. To turn off the automatic indentation, put in your |vimrc|: > let vimrplugin_indent_commented = 0 < What string will be added to the beginning of the line depends on the values of vimrplugin_indent_commented and r_indent_ess_comments according to the table below (see |r-plugin-indenting|): > vimrplugin_indent_commented r_indent_ess_comments string 1 0 # 0 1 # 1 1 ## 0 0 ### < 6.13. Sleep time (Windows only)~ *vimrplugin_sleeptime* The plugin gives to R a small amount of time to process the paste command. The default value is 0.2 second, but you should experiment different values. The example show how to adjust the value of sleeptime in your |vimrc|: > let vimrplugin_sleeptime = 0.1 < 6.14. Tmux and Screen configuration (Linux/Unix only)~ *vimrplugin_noscreenrc* *vimrplugin_notmuxconf* GVim (or Vim running R in an external terminal emulator) runs Tmux with a specially built configuration file. It also appends some arguments to |g:ScreenShellTmuxInitArgs|. If you want to use your own ~/.tmux.conf and |g:ScreenShellTmuxInitArgs|, put in your |vimrc|: > let vimrplugin_notmuxconf = 1 < If you want to use your own ~/.screenrc, put in your vimrc: > let vimrplugin_noscreenrc = 1 < If you opted for using your own configuration file, the plugin will write a minimum configuration which will set the value of two environment variables required for the communication with R and source your own configuration file (either ~/.tmux.conf or ~/.screenrc). 6.15. Integration with screen.vim plugin (Linux/Unix only)~ *vimrplugin_screenplugin* *vimrplugin_screenvsplit* *vimrplugin_tmux* *vimrplugin_only_in_tmux* The screen.vim plugin supports both GNU Screen and Tmux, but only Tmux allows you to split the terminal vertically (that is, to have the panels side by side). Please read |screen-intro| and |screen-shell-vertical| for details. By default, the Vim-R-plugin will tell the screen.vim plugin to split the terminal horizontally. If you prefer to split it vertically put in your |vimrc|: > let vimrplugin_screenvsplit = 1 let g:ScreenImpl = 'Tmux' < By default, when running in a terminal emulator, the Vim-R-plugin uses the screen.vim plugin if it is installed and, by default, it will use Tmux instead of GNU Screen. Tmux was chosen as default because it may split the terminal vertically and its regions are easier to resize. If you want that the R Console starts with a specific width, put in your |vimrc| your preferred value: > let g:ScreenShellWidth = 80 < If both GNU Screen and Tmux are installed but you prefer to use the GNU Screen application, put in your |vimrc|: > let vimrplugin_tmux = 0 < Start Vim and do the command <LocalLeader>rf. The screen.vim plugin will split the terminal in two regions and will run R in one of them. If you always prefer to start Tmux before Vim (see |r-plugin-tmux|) you may want to set the value of |vimrplugin_only_in_tmux| as below: > let vimrplugin_only_in_tmux = 1 < With the above option, the Vim-R-plugin will not start R if not running in a Tmux session, and it will warn you about that. If you have the screen.vim plugin installed but prefer do not integrate it with the Vim-R-plugin you will need to add the following to your |vimrc|: > let vimrplugin_screenplugin = 0 < 6.16. Integration with AppleScript (OS X only)~ *vimrplugin_applescript* In Mac OS X, the plugin will try to send commands to R gui using AppleScript. If you prefer to run R and Vim in the same terminal emulator split in two regions (Vim and R), put in your |vimrc|: > let vimrplugin_applescript = 0 < If you prefer to have R running in an external terminal emulator, put in your |vimrc|: > let vimrplugin_applescript = 0 let vimrplugin_screenplugin = 0 < 6.17. Special R functions~ *vimrplugin_listmethods* *vimrplugin_specialplot* The R function args() lists the arguments of a function, but not the arguments of its methods. If you want that the plugin calls the function .vim.list.args() after <LocalLeader>ra, you have to add to your |vimrc|: > let vimrplugin_listmethods = 1 < By default, R makes a scatterplot of numeric vectors. The function .vim.plot() do both a histogram and a boxplot. The function can be called by the plugin after <LocalLeader>rg if you put the following line in your |vimrc|: > let vimrplugin_specialplot = 1 < 6.18. maxdeparse~ *vimrplugin_maxdeparse* You can set the argument maxdeparse to be passed to R's source() function. Example: > let vimrplugin_maxdeparse = 300 < 6.19. LaTeX command~ *vimrplugin_latexcmd* *vimrplugin_sweaveargs* On Windows, the plugin calls tools::texi2pdf() to build the pdf from the generated .tex file. On Linux/Unix, by default, Vim calls pdflatex to produce a pdf document from the .tex file produced by the R Sweave command. You can use the option vimrplugin_latexcmd to change this behavior. Example: > let vimrplugin_latexcmd = "latex" < If you want to pass arguments do the Sweave() function, set the value of the vimrplugin_sweaveargs variable. 6.20. Never unmake the R menu and tool bar buttons~ *vimrplugin_never_unmake_menu* Use this option if you want that the menu item R and the R related tool bar buttons are not deleted when you change from one buffer to another, for example, when going from an .R file to a .txt one: > let vimrplugin_never_unmake_menu = 1 < When this options is enabled all menu items are created regardless of the file type. 6.21. Map 'r'~ *vimrplugin_map_r* If the variable |vimrplugin_map_r| exists, the plugin will map the letter 'r' to send lines to R when there are visually selected lines, for compatibility with the original plugin. To activate this option, insert the following into |vimrc|: > let vimrplugin_map_r = 1 < You may want to add the following three lines to your |vimrc| which were in Johannes Ranke's plugin and will increase compatibility with code edited with Emacs: > set expandtab set shiftwidth=4 set tabstop=8 < 6.22. Add ^A^K to the beginning of commands~ *vimrplugin_ca_ck* When one types <C-a> in the R Console the cursor goes to the beginning of the line and one types <C-k> the characters to the right of the cursor are deleted. This is useful to avoid characters left on the R Console being mixed with commands sent by Vim. However, sending <C-a> may be problematic if using either Tmux or GNU Screen in some systems. The Vim-R-plugin will add <C-a><C-k> to every command if you put in your |vimrc|: > let vimrplugin_ca_ck = 1 < 6.23. Open PDF after processing rnoweb file~ *vimrplugin_openpdf* *vimrplugin_openpdf_quietly* *vimrplugin_openhtml* *vimrplugin_strict_rst* The plugin will try to open automatically the pdf file generated by pdflatex, after either Sweave() or knit(), if you put in your |vimrc|: > let vimrplugin_openpdf = 1 < If you use Linux or other Unix and eventually use the system console (without the X server) you may want to put in your |vimrc|: > ifDISPLAY != ""
let vimrplugin_openpdf = 1
endif
<
Note: If the pdf is already open, some pdf readers will automatically update
the pdf; others will lock the pdf file and prevent R from successfully
compiling it again.

The application used to open the pdf may not be the same when the pdf is open
by R (when vimrplugin_openpdf = 1) and when you open it manually with
<LocalLeader>op key binding. If you are using Linux/Unix, you can change the
pdf reader by setting the value of the environment variable R_PDFVIEWER. This will affect both Vim and R. On Linux/Unix, when vimrplugin_openpdf = 1, the application used to open the pdf may be quite verbose, printing many lines of useless diagnostic messages in the R Console. Put the following in your |vimrc| to inhibit these messages (and all useful error messages): > let vimrplugin_openpdf_quietly = 1 < If editing an Rmd file, you can produce the html result with <LocalLeader>kh. The html file will be automatically opened if you put the following in your |vimrc|: > let vimrplugin_openhtml = 1 < By default, the Vim-R-plugin sends the command render_rst(strict=TRUE) to R before using R's knit() function to convert an Rrst file into an rst one. If you prefer the non strict rst code, put the following in your |vimrc|: > let vimrplugin_strict_rst = 0 < 6.24. Allow R commands in insert mode~ *Vimrplugin_insert_mode_cmds* Vim-R commands are designed to work in insert mode as well as normal mode. However, depending on your <LocalLeader>, this can make it very difficult to write R packages or Sweave files. For example, if <LocalLeader> is set to the '\' character, typing '\dQuote' in a .Rd file tries to send the command! The option vimrplugin_insert_mode_cmds disables commands in insert mode. To use it, add the following in your |vimrc|: > let g:vimrplugin_insert_mode_cmds = 0 < The default value is 1, for consistency with earlier versions. 6.25. Show/remove hidden objects~ *vimrplugin_allnames* *vimrplugin_rmhidden* Hidden objects are not included in the list of objects for omni completion. If you prefer to include them, put in your |vimrc|: > let g:vimrplugin_allnames = 1 < Hidden objects are removed from R workspace when you do <LocalLeader>rm. If you prefer to remove only visible objects, put in your |vimrc|: > let g:vimrplugin_rmhidden = 0 < ============================================================================== *r-plugin-key-bindings* 7. Custom key bindings~ When creating custom key bindings for the Vim-R-plugin, it is necessary to create three maps for most functions because the way the function is called is different in each Vim mode. Thus, key bindings must be made for Normal mode, insert mode, and visual mode. To customize a key binding you should put in your |vimrc| something like: > nmap <F2> <Plug>RStart imap <F2> <Plug>RStart vmap <F2> <Plug>RStart < The above example shows how to change key binding used to start R from <LocalLeader>rf to <F2>. Only the custom key bindings for Normal mode are shown in Vim's menu, but you can type |:map| to see the complete list of current mappings, and below is the list of the names for custom key bindings (the prefix RE means "echo"; RD, "cursor down"; RED, both "echo" and "down"): Star/Close R~ RStart RVanillaStart RCustomStart RClose RSaveClose Clear R console~ RClearAll RClearConsole Edit R code~ RCommentLine RRightComment RCompleteArgs RIndent Send line or part of it to R~ RSendLine RDSendLine RSendLAndOpenNewOne RNLeftPart RNRightPart RILeftPart RIRightPart Send code to R console~ RSendSelection RESendSelection RDSendSelection REDSendSelection RSendMBlock RESendMBlock RDSendMBlock REDSendMBlock RSendParagraph RESendParagraph RDSendParagraph REDSendParagraph RSendFunction RESendFunction RDSendFunction REDSendFunction RSendFile RESendFile Send command to R~ RHelp RPlot RSPlot RShowArgs RShowEx RShowRout RObjectNames RObjectPr RObjectStr RSetwd RSummary RListSpace Support to Rnoweb, Rmd, Rrst~ RSendChunk RDSendChunk RESendChunk REDSendChunk RBibTeX RBibTeXK RSweave RKnit RMakeHTML RMakeODT RMakePDF RMakePDFK ROpenPDF RSpinFile Object browser~ RUpdateObjBrowser ROpenLists RCloseLists The completion of function arguments only happens in Insert mode. To customize its keybind you should put in your |vimrc| something as in the example: > imap <C-A> <Plug>RCompleteArgs < The plugin also contains a function called RAction which allows you to build ad-hoc commands to R. This function takes the name of an R function such as "levels" or "table" and the word under the cursor, and passes them to R as a command. For example, if your cursor is sitting on top of the object called gender and you call the RAction function, with an argument such as levels, Vim will pass the command levels(gender) to R, which will show you the levels of the object gender. To make it even easier to use this function, you could write a custom key binding that would allow you to rapidly get the levels of the object under your cursor. Add the following to your |vimrc| to have an easy way to pass R the levels command: > map <silent> <LocalLeader>rk :call RAction("levels")<CR> map <silent> <LocalLeader>t :call RAction("tail")<CR> map <silent> <LocalLeader>h :call RAction("head")<CR> < Then if you type <LocalLeader>rk R will receive the command > levels(myObject) < You should replace <LocalLeader>rk with the key binding that you want to use and "levels" with the R function that you want to call. If the command that you want to send does not require an R object as argument, you can create a shortcut to it by following the example: > map <silent> <LocalLeader>s :call SendCmdToR("search()") < ============================================================================== *r-plugin-files* 8. Files~ The following files are part of the plugin and should be in your ~/.vim directory after the installation: autoload/rcomplete.vim bitmaps/RClearAll.bmp bitmaps/RClearAll.png bitmaps/RClear.bmp bitmaps/RClear.png bitmaps/RClose.bmp bitmaps/RClose.png bitmaps/ricon.png bitmaps/ricon.xbm bitmaps/RListSpace.bmp bitmaps/RListSpace.png bitmaps/RSendBlock.bmp bitmaps/RSendBlock.png bitmaps/RSendFile.bmp bitmaps/RSendFile.png bitmaps/RSendFunction.bmp bitmaps/RSendFunction.png bitmaps/RSendLine.bmp bitmaps/RSendLine.png bitmaps/RSendParagraph.bmp bitmaps/RSendParagraph.png bitmaps/RSendSelection.bmp bitmaps/RSendSelection.png bitmaps/RStart.bmp bitmaps/RStart.png doc/r-plugin.txt ftdetect/r.vim ftplugin/rhelp.vim ftplugin/rnoweb.vim ftplugin/r.vim ftplugin/rbrowser.vim ftplugin/rmd.vim ftplugin/rrst.vim indent/r.vim indent/rhelp.vim indent/rnoweb.vim indent/rmd.vim indent/rrst.vim r-plugin/common_buffer.vim r-plugin/common_global.vim r-plugin/functions.vim r-plugin/objlist/ r-plugin/r.snippets r-plugin/tex_indent.vim r-plugin/vimcom.py r-plugin/windows.py syntax/rbrowser.vim syntax/rout.vim syntax/r.vim syntax/rmd.vim syntax/rrst.vim ============================================================================== *r-plugin-tips* 9. FAQ and tips~ 9.1. Is it possible to stop R from within Vim?~ Sorry, it is not possible. The plugin can only send the quit() command. If you want to stop R, you have to press ^C into R's terminal emulator. 9.2. Html help and custom pager~ If you prefer to see help pages in an html browser, put in your ~/.Rprofile: > options(help_type = "html") < and in your |vimrc| (see |vimrplugin_vimpager|): > let vimrplugin_vimpager = "no" < 9.3. How do marked blocks work?~ *r-plugin-showmarks* Vim allows you to put several marks (bookmarks) in buffers. The most commonly used marks are the lowercase alphabet letters. If the cursor is between any two marks, the plugin will send the lines between them to R. If the cursor is above the first mark, the plugin will send from the beginning of the file to the mark. If the cursor is below the last mark, the plugin will send from the mark to the end of the file. The mark above the cursor is included and the mark below is excluded from the block to be sent to R. To create a mark, press m<letter> in Normal mode. We recommended the use of ShowMarks plugin which show what lines have marks defined. The plugin is available at: http://www.vim.org/scripts/script.php?script_id=152 This plugin makes it possible to visually manage your marks. You may want to add the following two lines to your |vimrc| to customize ShowMarks behavior: > let marksCloseWhenSelected = 0 let showmarks_include = "abcdefghijklmnopqrstuvwxyz" < 9.4. Use snipMate~ *r-plugin-snippets* You probably will want to use the snipMate plugin to insert snippets of code in your R script. The plugin may be downloaded from: http://www.vim.org/scripts/script.php?script_id=2540 The snipMate plugin does not come with snippets for R, but you can copy the files r.snippets and rmd.snippets that ship with the Vim-R-plugin (look at the r-plugin directory) to the snippets directory. The files have only a few snippets, but they will help you to get started. If you usually edit rnoweb files, you may also want to create an rnoweb.snippet by concatenating both tex.snippets and r.snippets. 9.5. Easier key bindings for most used commands~ *r-plugin-bindings* The most used commands from Vim-R-plugin probably are "Send line" and "Send selection". You may find it a good idea to map them to the space bar in your |vimrc| (suggestion made by Iago Mosqueira): > vmap <Space> <Plug>RDSendSelection nmap <Space> <Plug>RDSendLine < You may also want to remap <C-x><C-o>: http://stackoverflow.com/questions/2269005/how-can-i-change-the-keybinding-used-to-autocomplete-in-vim 9.6. Remap the <LocalLeader>~ *r-plugin-localleader* People writing Rnoweb documents may find it better to use a comma or other key as the <LocalLeader> instead of the default backslash (see |maplocalleader|): > let maplocalleader = "," < 9.7. Use a tags file to jump to function definitions~ *r-plugin-tagsfile* Vim can jump to a function definition if it finds a "tags" file with the information about the place where the function is defined. To generate the tags file, use the R function rtags(), which will build an Emacs tags file. If Vim was compiled with the feature |emacs_tags|, it will be able to read the tags file. Otherwise, you can use the function etags2ctags() from the script located at ~/.vim/r-plugin/etags2ctags.R to convert the Emacs tags file into a Vim's one. To jump to a function definition, put the cursor over the function name and hit CTRL-]. Please, read |tagsrch.txt| for details on how to use tags files, specially the section |tags-option|. You could, for example, download and unpack R's source code, start R inside the ~/.vim directory and do the following command: > rtags(path = "/path/to/R/source/code", recursive = TRUE, ofile = "RTAGS") < Then, you would quit R and do the following command in the terminal emulator: > ctags --languages=C,Fortran,Java,Tcl -R -f RsrcTags /path/to/R/source/code < Finally, you would put the following in your |vimrc|, inside an |autocmd-group|: > autocmd FileType r set tags+=~/.vim/RTAGS,~/.vim/RsrcTags autocmd FileType rnoweb set tags+=~/.vim/RTAGS,~/.vim/RsrcTags < Note: While defining the autocmd, the RTAGS path must be put before RsrcTags. Example on how to test whether your setup is ok: 1. Type "mapply()" in an R script and save the buffer. 2. Press CTRL-] over "mapply" (Vim should jump to "mapply.R"). 3. Locate the string "do_mapply", which is the name of a C function. 4. Press CTRL-] over "do_mapply" (Vim sould jump to "mapply.c"). 9.8. Indenting setup~ *r-plugin-indenting* Note: In Normal mode, type |==| to indent the current line and gg=G to format the entire buffer (see |gg|, |=| and |G| for details). These are Vim commands; they are not specific to R code. The Vim-R-plugin includes a script to automatically indent R files. By default, the script aligns function arguments if they span for multiple lines. If you prefer do not have the arguments of functions aligned, put in your |vimrc|: > let r_indent_align_args = 0 < By default, all lines beginning with a comment character, #, get the same indentation level of the normal R code. Users of Emacs/ESS may be used to have lines beginning with a single # indented in the 40th column, ## indented as R code, and ### not indented. If you prefer that lines beginning with comment characters are aligned as they are by Emacs/ESS, put in your |vimrc|: > let r_indent_ess_comments = 1 < If you prefer that lines beginning with a single # are aligned at a column different from the 40th one, you should set a new value to the variable r_indent_comment_column, as in the example below: > let r_indent_comment_column = 30 < By default any code after a line that ends with "<-" is indented. Emacs/ESS does not indent the code if it is a top level function. If you prefer that the Vim-R-plugin behaves like Emacs/ESS in this regard, put in your |vimrc|: > let r_indent_ess_compatible = 1 < Below is an example of indentation with and without this option enabled: > ### r_indent_ess_compatible = 1 ### r_indent_ess_compatible = 0 foo <- foo <- function(x) function(x) { { paste(x) paste(x) } } < Notes: (1) Not all code indented by Emacs/ESS will be indented by the Vim-R-plugin in the same way, and, in some circumstances it may be necessary to make changes in the code to get it properly indented by Vim (you may have to either put or remove braces and line breaks). (2) Indenting is not a file type plugin option. It is a feature defined in indent/r.vim. That is why it is documented in this section. 9.9. Folding setup~ *r-plugin-folding* Vim has several methods of folding text (see |fold-methods| and |fold-commands|). To enable the syntax method of folding for R files, put in your |vimrc|: > let r_syntax_folding = 1 < With the above option, Vim will load R files with all folds closed. If you prefer to start editing files with all folds open, put in your |vimrc|: > set nofoldenable < Notes: (1) Enabling folding may slow down Vim. (2) Folding is not a file type plugin option. It is a feature defined in syntax/r.vim. Note: Indentation of R code is very slow because the indentation algorithm sometimes goes backwards looking for an opening parenthesis or brace or for the beginning of a "for", "if" or "while" statement. This is necessary because the indentation level of a given line depends on the indentation level of the previous line, but the previous line is not always the line above. It's the line where the statement immediately above started. Of course someone may develop a better algorithm in the future. 9.10. Highlight chunk header as R code~ By default, Vim will highlight chunk headers of RMarkdown and RreStructuredText with a single color. When the code is processed by knitr, chunk headers should contain valid R code and, thus, you may want to highlight them as such. You can do this by putting in your |vimrc|: > let rrst_syn_hl_chunk = 1 let rmd_syn_hl_chunk = 1 < 9.11. Automatically close parenthesis~ Some people want Vim automatically inserting a closing parenthesis, bracket or brace when an open one has being typed. The page below explains how to achieve this goal: http://vim.wikia.com/wiki/Automatically_append_closing_characters 9.12. Automatic line breaks~ By default, Vim breaks lines when you are typing if you reach the column defined by the 'textwidth' option. If you prefer that Vim does not break the R code automatically, breaking only comment lines, put in your |vimrc|: > autocmd FileType r setlocal formatoptions=cq < 9.13. Vim with 256 colors in a terminal emulator (Linux/Unix only)~ If you want 256 colors support in Vim, install the package ncurses-term. Then put in your ~/.bashrc: > if [ "x" != "xDISPLAY" ]
then
if [ "screen" = "$TERM" ] then export TERM=screen-256color else export TERM=xterm-256color fi fi < Finally, put in your |vimrc|: > if &term =~ "xterm" || &term =~ "256" ||$DISPLAY != ""
set t_Co=256
endif
colorscheme your_prefered_color_scheme
<
You have to search the internet for color schemes supporting 256 colors,
|:colorscheme| to try them all before setting your preference in your |vimrc|.

9.14. Run your Makefile from within R~

Do you have many Rnoweb files included in a master tex or Rnoweb file and use
a Makefile to build the pdf? You may consider it useful to put the following
>
<

You may want to edit your ~/.Rprofile. Two common options are the use of GVim
as the text editor and the use of Vim as pager. Example for Linux with these
two options and some others:
>
if(interactive()){
library(colorout)
library(setwidth)
options(vimcom.verbose = 1, vimcom.allnames = TRUE)
if(Sys.getenv("VIMRPLUGIN_TMPDIR") != "")
library(vimcom)
if(Sys.getenv("TERM") != "linux" && Sys.getenv("TERM") != "")
setOutputColors256(verbose = FALSE)
if(nchar(Sys.getenv("DISPLAY")) > 1){
grDevices::X11.options(width = 4.5, height = 4, ypos = 0,
xpos = 1000, pointsize = 10)
options(editor = 'gvim -f -c "set ft=r"')
options(pager = "gvim -c 'set ft=rdoc' -")
} else {
options(editor = 'vim -c "set ft=r"')
options(pager = "vim -c 'set ft=rdoc' -")
}
}
<
The test for the environment variable DISPLAY is useful if you eventually use
the plugin over ssh or on the Linux console.

The X11.options() is used to choose the position and dimensions of the X11
graphical device. You can also install the application wmctrl and create
shortcuts in your desktop environment to the commands
>
wmctrl -r "R Graphics" -b add,above
wmctrl -r "R Graphics" -b remove,above
<
which will toggle the "always on top" state of the X11 device window.
Alternatively, you can right click on the X11 device window title bar and
choose "Always on top". This is useful to emulate a feature present in R IDEs
which can display R plots in a separate panel. Although we can not embed an R
graphical device in Vim, we can at least make it always visible over the
terminal emulator or the GVim window.

An example for Windows:
>
if (interactive()) {
local({
options(editor = '"C:/Program Files (x86)/Vim/vim73/gvim.exe" "-c" "set filetype=r"')
options(help_type = "html")
})
}
<

9.16. Debugging R functions~

The Vim-R-Plugin does not have debugging facilities, but you may want to use
the R package "debug":
>
install.packages("debug")
library(debug)
mtrace(function)
<
Once the library is installed and loaded, you should use mtrace(function_name)
to enable the debugging of a function. Then, the next time that the function
is called it will enter in debugging mode. Once debugging a function, you can
hit <Enter> to evaluate the current line, go(n) to go to line n in the
function and qqq() to quit the function (See debug's help for details). A
useful tip is to click on the title bar of the debug window and choose "Always
on top" or a similar option provided by your desktop manager.

There is also the R package "edtdbg" which aims to integrate R debugging
facilities with Vim.

9.17. Turn the R-plugin into a global plugin~
*r-plugin-global*
The Vim-R-plugin is a file type plugin. If you want its functionality
available for all file types, then go to your ~/.vim/plugin directory and
create a symbolic link to ~/.vim/r-plugin/global_r_plugin.vim. That is, type
the following in a terminal emulator:
>
cd ~/.vim/plugin/
ln -s ../r-plugin/global_r_plugin.vim
<
On Windows, you probably will have to make a copy of the file to the
~/vimfiles/plugin directory.

9.18. Disable syntax highlight of R functions~

If you want to disable the syntax highlight of R functions edit the file
~/.vim/r-plugin/functions.vim and delete all lines, but do not delete the
file.

9.19. Tips for knitr users~
*knitr*
If you are using knitr with option cache=TRUE, you may want from time to time
to delete all objects in R workspace and all files in the cache directory. If
you want to use <LocalLeader>kr in Normal mode for this, put in your |vimrc|:
>
<
When generating pdfs out of Rmd-files, you can send options to pandoc. State
them in your vimrc. For example

let vimrplugin_pandoc_args = "--toc -V lang=german"

9.20. Start Tmux and Vim at once~

If you always prefer to run Tmux before running Vim you may want to put in
>
function tvim(){ tmux new-session "vim @" ; } < Then you will be able to start Vim inside a Tmux session by typing: > tvim filename.R < 9.21. Integration with the Conque Shell plugin~ *r-plugin-conque* In addition to being integrated with the screen.vim plugin the Vim-R-plugin can also use the Conque Shell plugin, but the Conque Shell still has some important bugs and Vim has limitations that make the use of Conque Shell not fully satisfying. The most important bug of Conque Shell is that it sometimes do not show the complete output of an R command. This problem happens more frequently when there are non ascii characters in the output. The two most important Vim limitations are: - We cannot scroll the windows of a buffer that is not being edited and, thus, we have to go to the R Console buffer to scroll it. This is a problem if we are running an R command that slowly generates a lot of output because the shell buffer does not scroll when there is new output but it is not the currently active buffer. - Vim does not have a timer which would make the Conque Shell more efficient. Vim uses the same variable, 'updatetime', to do both save swap files and trigger |CursorHold| events. These limitations will be solved only if someone with good knowledge of C programming writes patches to Vim source code and the patches are accepted by the Vim developer. In addition to these two limitations, the automatic update of the Object Browser is disabled when Conque Shell is active because the cursor placement becomes unstable. Anyway, if you want to try the Conque Shell, install it from http://www.vim.org/scripts/script.php?script_id=2771 do not load the R package "colorout", and put in your |vimrc|: > let vimrplugin_ca_ck = 0 let vimrplugin_applescript = 0 let vimrplugin_screenplugin = 0 let vimrplugin_conqueplugin = 1 < You may also want to put the following Conque options in your |vimrc| (look at the Conque Shell documentations for details): > let ConqueTerm_CWInsert = 1 let ConqueTerm_Color = 0 let ConqueTerm_ReadUnfocused = 1 < By default, the window will be split horizontally. Put the following in your |vimrc| if you prefer to split the window vertically: > let vimrplugin_conquevsplit = 1 < You may also need to change the time that the Conque Shell waits for R output. After a command is sent to the Conque buffer, the Conque Shell plugin waits 100 milliseconds (on Linux) or 200 milliseconds (on Windows) before reading R's output. Longer values for the waiting time will increase the chances that the output of R commands will be immediately shown in the R Console. To set a different waiting time, change the value of vimrplugin_conquesleep in your |vimrc| as in the example: > let vimrplugin_conquesleep = 300 < To manually scroll the R Console buffer, put the following in your |vimrc| (replace <F5> with your preferred key): > nmap <F5> :call RScrollTerm()<CR> < Then, you will be able to scroll the R Console buffer at any time by pressing the <F5> key in Normal mode. Of course, you should replace <F5> with your preferred key. With the Conque Shell, the option |vimrplugin_nosingler| is ignored, and, by default, the object browser window will be created at the right of the R Console window. The same highlighting scheme used for .Rout files is applied to the R Console when using the Conque Shell plugin to run R inside a Vim's buffer. For one hand, we do not need to highlight R commands in the Console if they were sent by the plugin from an R script buffer since we have the code highlighted in the script buffer and in the Console we want to pay attention to the output. A too colorful highlighting scheme would be distracting. On the other hand, if we were typing commands directly in the Console it would be beneficial to have the R syntax highlighted. 9.22. Integration with vimshell~ *r-plugin-vimshell* Vimshell is still under development, but if you want to integrate it with the Vim-R-plugin, put in your |vimrc|: > let vimrplugin_screenplugin = 0 let vimrplugin_ca_ck = 0 let vimrplugin_applescript = 0 let vimrplugin_vimshell = 1 < If you want the automatic updating of the Object Browser even if running Vim in a terminal emulator, you have to start Vim with the |--servername| argument. Example: > vim --servername OBJBR file.R < ============================================================================== *r-plugin-news* 10. News~ 0.9.9.1 (2012-12-11) * Enable mouse on Tmux again. 0.9.9 (2012-12-03) * New commands: :Rinsert and :Rformat. * Automatically update the Object Browser in GVim. * On MS Windows, don't raise the R Console before sending CTRL-V to it. * Search for vimcom in both IPv4 and IPv6 ports (thanks to Zé Loff for writing the patch). 0.9.8 (2012-10-13) * Open PDF automatically after processing Rnoweb file if vimrplugin_openpdf = 1 (thanks to Tomaz Ficko for suggesting the feature). Open it quietly if vimrplugin_openpdf_quietly = 1. Open it manually with \op. * Open HTML automatically after processing either Rmd or Rrst file if vimrplugin_openhtml = 1. Generate strict rst code if vimrplugin_strict_rst = 1. * Remove option vimrplugin_knitargs. * Start last R if there is more than one installed on Windows (thanks to Alex Zvoleff for reporting the bug and writing the patch). * Alex Zvoleff added support to Rrst file type. * michelk added support to Rmd file type. * For Rnoweb, Rmd and Rrst file types, CTRL-X CTRL-A completes knitr chunk options if the cursor is inside the chunk header. * New option: vimrplugin_rmhidden. * New option: vimrplugin_insert_mode_cmds (thanks to Charles R. Hogg III). * New command :RAddLibToList to add the objects of specific libraries to omnicompletion. * Thanks to genrich and NagatoPain for other bug fixes and code improvements. * New option: vimrplugin_assign_map. The option vimrplugin_underscore was renamed to vimrplugin_assign 0.9.7 (2012-05-04) * Use the R package vimcom: - Automatic update of the Object Browser when running R in a Tmux session. - The following options are now set on the vimcom R package and no longer in the Vim-R-plugin: allnames, open_df, and open_list. - New command in normal and visual modes when on the Object Browser: "d" deletes objects and detach libraries. New option: vimrplugin_ob_sleep. * New option, vimrplugin_external_ob, to open the Object Browser in a Tmux pane in the external terminal running R. * New command :Rhelp (thanks for Nir Atias for suggesting the new feature). * Remove the command :RUpdateObjListAll because Vim may not load the syntax file if it is too big. * Add support to knitr package. * New command :RSourceDir. * New key bindings \r<Left> and \r<Right>. * Correctly send selected blocks. 0.9.6 (2011-12-13) * Fix path to R source() command on Windows. * New default value of vimrplugin_vimpager = "tab". * New default value of vimrplugin_objbr_place = "editor,right" * Autocompletion of function arguments with <C-X><C-A>. 0.9.5 (2011-12-07) * Changed the way that blocks are sent to R. * Added "terminal" to the list of known terminal emulators (thanks for "i5m" for the patch). * Use Tmux to start the Object Browser beside the R console if vimrplugin_objbr_place =~ "console". * The file r-plugin/omniList was renamed to r-plugin/omnils because its field separator changed. 111114 (2011-11-14) * Changed key binding for commenting/uncommenting code from \cc to \xx. * Added function SendChunkToR() and its corresponding key bindings: \cc, \ce, \cd and \ca (thanks to Xavier Fernández i Marín for suggesting the feature). * New option (vimrplugin_ca_ck) was created to fix bug reported by Xavier Fernández i Marín: spurious ^A^K being added to lines sent to R. * Don't blink the menu and toolbar buttons when doing omni completion. * Use Tmux to run R in an external terminal emulator. 111014 (2011-10-14) * Fixed spell check bug in R documentation files (.Rd). * Fixed beep bug when sending commands to R. * New option: vimrplugin_notmuxconf. * Fixed bug when starting tmux before vim: the environment variable VIMRPLUGIN_TMPDIR was not being set. Thanks to Michel Lang for reporting the bug and helping to track its source, and thanks to Eric Dewoestine for explaining how to fix the bug. * Fixed bug in code indentation after unbalanced brackets and parenthesis when r_indent_align_args = 0 (thanks to Chris Neff and Peng Yu for reporting the bugs). * Really make the use of AppleScript the default on OS X (thanks for Jason for reporting the bug). 110805 (2011-08-05) * New option: vimrplugin_tmux. * Set Tmux as the default instead of either GNU Screen or Conque Shell. * Document Tmux as the preferred way of running the plugin on Linux. * Vim-LaTeX-suite plugin can be used with Rnoweb files without any additional configuration. The necessary code was added to the ftplugin/rnoweb.vim. * Added count argument to normal mode commands gn and gN (thanks to Ivan Bezerra for the suggestion). 110614 (2011-06-14) * When doing the command \rh, the plugin tries to show the help for the method corresponding to the class of the object passed as argument to the function. The same with \rp (thanks to Thomas Scheike for suggesting the feature). * Removed script rpager.sh. * Added script global_r_plugin.vim to allow the use of the plugin with any file type. 110222 (2011-02-22) * Added syntax/rhelp.vim. * New command for rnoweb files: BibTeX current file (\sb). * New commands for the object browser: open visible lists (\r=) and close visible lists (\r-). * Reorganization of the GUI menu. 110208 (2011-02-08) * Fixed bug in "else if" constructions (thanks to Dan Kelley for reporting the bug). * Support for commenting/uncommenting lines. 110203 (2011-02-03) * Fixed bug in :RUpdateObjList when the function arguments included S4 objects (thanks to Gerhard Schoefl for reporting the bug). * Improvements in indentation of R code (thanks to Dan Kelley for finding and reporting indentation bugs and testing many versions of indent/r.vim). * New indentation options: r_indent_align_args, r_indent_ess_comments, r_indent_comment_column, and r_indent_ess_compatible. * New file: indent/rhelp.vim. 110117 (2011-01-17) * Fixed indentation bug in Rnoweb files (thanks to Dan Kelley for reporting the bug). 101217 (2010-12-17) * Renamed the function SendCmdToScreen to SendCmdToR. * Clear the current line in the R console before sending a new line. * Always starts R on the script's directory. * Don't send "^@" as part of a paragraph in rnoweb files (thanks to Fabio
Correa for reporting the bug).
* More useful warning message when PyWin32 isn't installed.
* Initial support to AppleScript on Mac OS X (thanks to Vincent Nijs for
writing and testing the code).

101121 (2010-11-21)
* Fix for when whoami returns domain name on Windows (thanks to "Si" for
fixing the bug).

101118 (2010-11-18)
* New command:  :RUpdateObjListAll.
* New option: vimrplugin_allnames.
* Allow the use of Python 3.1 on Windows.
* Minor improvements in indentation of R code.
* The file r-plugin/omni_list was renamed to r-plugin/omniList because its
field separator changed to ";".
* Fixed bug that was causing ^H to be exhibited in the R documentation in
some systems. (Thanks to Helge Liebert for reporting the problem).

101107 (2010-11-07)
* New feature: complete chunk block when '<' is pressed in rnoweb files.
* New option: vimrplugin_rnowebchunk.
* New key bindings in Normal mode for Rnoweb files: gn (go to next R code
chunk) and gN (go to previous R code chunk).
* New command:  :RBuildTags.
* Added fold capability to syntax/r.vim.
* Improved indentation of rnoweb files: thanks to Johannes Tanzler for
writing the tex.vim indent script and for permitting its inclusion in the
Vim-R-plugin.
* R CMD BATCH now is called with --no-restore --no-save (key binding \ro).
* The file r-plugin/omnilist now has an additional field and was renamed as
omni_list.
* Use 64 bit version of R by default on Windows if the directory bin/x64
exists.
* New Windows only option: vimrplugin_i386.

101025 (2010-10-25)
* New option: vimrplugin_routmorecolors.
* Fixed bug in the Object Browser when a data.frame or list had just one
element (thanks to Jan Larres for reporting the bug).
* Do not copy omnilist and functions.vim to ~/.vim/r-plugin if the directory
where the plugin is installed is writable (thanks to Jan Larres for the
suggestion).

101023 (2010-10-23)
* New options: vimrplugin_objbr_place and vimrplugin_objbr_w.
* New default value: vimrplugin_vimpager = "vertical"
* The R help can now be seen in a Vim buffer on MS Windows.
* Fix width of help text when R version >= 2.12.0.
* Implemented actions in the Object Browser: summary, print, etc...
* Browse libraries objects in Object Browser.

101016 (2010-10-16)
* Minor bug fixes in the Object Browser.

101015 (2010-10-15)
* New feature: Object Browser.
* Conque Shell will be used if installed unless explicitly told otherwise in
the vimrc.
* New valid value for vimrplugin_vimpager: "tabnew"

100923 (2010-09-23)
* New option: vimrplugin_vimpager.
* Do not let Vim translate "File" in R menu.
* Fixed bug when the option vimrplugin_r_path was used (thanks to Asis Hallab
for reporting the bug),
* Fixed bug (E687) when user created custom key binding (thanks to Philippe
Glaziou for reporting the bug).

100917 (2010-09-17)
* Changed the use of vimrplugin_r_path: now the option includes only the
directory part of the path.
* Initial support to Conque Shell plugin. Thanks to "il_principe orange" for
suggesting the use of Conque Shell, "ZyX-I" for writing the initial code to
use Conque Shell, and Nico Raffo for writing the plugin and additional code
to integrate both plugins.
* New options: vimrplugin_conqueplugin and vimrplugin_conquevsplit.
* New option: vimrplugin_r_args.
* Fixed bug when the plugin was installed in a directory other than ~/.vim
* Initial support for Vim-R communication on Windows using Python.

100825 (2010-08-25)
* Minor improvements in syntax highlighting.
* New option: vimrplugin_buildwait.
* New option: vimrplugin_r_path (thanks to Asis Hallab).

100803 (2010-08-03)
* Fixed bug in .Rsource name making in some systems.

100801 (2010-08-01)
* Dropped options vimrplugin_hstart and vimrplugin_browser_time.
* Minor bug fixes.

100730 (2010-07-30)
* Added menu item and key binding for run "R CMD BATCH" and open the
resulting ".Rout" file.
* Fixed bug when more than one Vim instance used the same file to send
multiple lines of code to R (thanks to Bart for reporting the bug).

100728 (2010-07-28)
* Adapted the plugin to allow the creation of a Debian package.

100719 (2010-07-19)
* Added options vimrplugin_listmethods and vimrplugin_specialplot.
* Improved syntax highlight of R batch output (.Rout files).
* No longer uses the external programs grep, awk and sed to build the
additional syntax file containing the list of functions.

100710 (2010-07-10)
* Fixed :RUpdateObjList bug when list had length 0.

100707 (2010-07-07)
* Fixed 'E329: No menu "R"' when more than one file were loaded simultaneously
by calling vim with either -p or -o parameters. Thanks to Peng Yu for
reporting the bug.
* Correctly recognize a newly created file with extension ".R" as an R script
file.

100521 (2010-05-12)
* Replaced "-t" with "--title" to make xfce4-terminal work again.

100512 (2010-05-12)
* Thanks to Tortonesi Mauro who wrote a patch to make the plugin work with
pathogen.vim.
* Added simple syntax highlight for .Rout files.
* Increased the time limit of RUpdateObjList to two minutes.
* Improvement in the syntax highlight based on code written by Zhuojun Chen.
* Thanks to Scott Kostyshak who helped to improve the documentation.
* Iago Mosqueira suggested that the plugin should be able to run one R process
for each Vim instance, and his suggestion was implemented with the option
vimrplugin_by_vim_instance.

091223 (2009-12-23)
* Syntax highlight for R functions.
* Added "info" field to omni completion (thanks to Ben Kujala for writing the
original code).

091016 (2009-10-16)
* The plugin now can run together with screen.vim, thanks to Eric Van
Dewoestine, the author of screen.vim, who added script integration to
screen.vim.
* Andy Choens has made many improvements on the documentation.
* Added the possibility of custom key binding creation to call any R function
with the word under cursor as argument.
* The key bindings related with Sweave are activated even if the file type is
not rnoweb.

091004 (2009-10-04)
* Jose Claudio Faria has begun to work in the project as co-author.
* Some ideas from Tinn-R project were ported to the plugin.
* The main menu has new items and the toolbar new icons.
* Documentation improvements.

090828 (2009-08-28)
* Faster startup.
* Better support for Rnoweb files: the cursor goes to '^<<' if the sent line
is '^@\$'.

090811 (2009-08-12)
* Now use screen instead of funnel.pl. The bugs and limitations related with
funnel.pl are solved.
* Deleted key binding for R-devel.
* Automatically detect available terminal emulators and choose one of them.
* By default, no longer calls help.start() the first time that CTRL-H is
pressed.

090810 (2009-08-10)
* Added R icons for some terminal emulators.
* Removed the script open-gvim-here. You may use Vim's option autochdir.
* Improved indentation script.
* Changed key binding from Shift-Enter, which doesn't work in any terminal, to
Alt-Enter, which at least works in xterm.

090610 (2009-06-11)
* The options expandtab, shiftwidth and tabstop are no longer set by the plugin.
* Better word detection before calling R's help().
* Fixed bug in underscore replacement.
* Fixed small bug in code indentation.
* Added two new plugin options: no underscore replacement and fixed name for
the pipe file instead of random one.

090523 (2009-05-23)
* Key bindings now are customizable.
* Default key binding for calling R's args() changed to Shift-F1.
* New R script rargs.R gives better results for generic functions than R's
args() called directly.

090519 (2009-05-20)
* Don't send large blocks of code to R to avoid xterm freezing.
* Automatically call help.start() after CTRL-H is pressed for the first time,
and wait 4 seconds for the browser start before calling R's help(). These
features are customizable.
* Fixed tags file script.

090516 (2009-05-16)
* Added ability to send function to R, revert the automatic conversion of "_"
into "<-" and call R's help().
* Added archive with some files to ease desktop integration, if desired.

090507 (2009-05-08)

vim:tw=78:ts=8:ft=help:norl

 本帖最后由 王钇 于 2013-1-8 21:03 编辑 VIM是个强大的编辑器，我对VIM的感触是，一旦形成了使用习惯，再用其它的文本编辑器都感觉很不自在，尤其是在移动光标，跳转编辑位置，以及删除文本行的时候。所以，在编写源代码时，总是寻找能够使用VIM方式的编辑器。以前在写Java代码时，使用最多的是NetBeans，它有一个叫做JVi的插件，对VI方式的操作支持得很好。目前学习R的过程中，RStudio还没有发现类似的编辑机制或插件。如果直接使用VIM也不错，但需要在RGUI和VIM之间切换，还需要多次使用source执行文件，非常不方便，这方面有一个VIM插件，叫VIM  R Plugin，即VIM的R插件，它可以在VIM中直接启动R环境，发送指定程序行或者全部文件给R，对于使用VIM的人来说非常方便，下面简要介绍一下它的安装和使用，但由于在不同平台下，安装VIM的R插件过程不尽相同，所以我打算先只介绍在Windows中安装和使用R插件。 （1）R插件的安装 R Plugin的安装首先要求系统中安装了VIM，对于最新版本的R plugin，需要VIM最新的7.3才能支持，可以从http://www.vim.org 下载7.3的Windows版本。安装完VIM之后，就可以安装R插件了，可以在http://www.vim.org/scripts/script.php?script_id=2628 下载最新的版本，目前的最新的版本号是0.9.9.1，下载对应zip文件，解压缩到硬盘的某个文件夹即可。这里假设将zip中所有的文件解压到c:\vrp目录下。 解压完成后，在Windows系统当前用户的主目录中，建立一个名为vimfiles的文件夹，把刚才解压得到的文件（本文是c:\vrp）拷贝到vimfiles文件夹中，这样R插件本身就算装好了。这里需要注意的是，Windows 7和Windows XP对当前用户的主目录设定不一样，对于XP用户，主目录是系统盘上（一般是C盘）的Document and Settings\<用户名>这个目录（注意<用户名>代表实际的用户名），而Windows 7则是系统盘中的Users/<用户名>这个目录（注意，如果用“我的电脑”或者资源管理器察看系统盘文件夹时，Users这个文件夹通常显示为“用户”这个中文名，实际上就是Users文件夹。另外，一定还要注意你当前登录Windows的用户名是什么，不要把vimfiles文件夹建错到别的用户名下面，可以通过控制面板中的用户查看当前的用户名。） （2）R插件的依赖软件的安装 R Plugin这个插件依赖于两个软件才能正常工作，一个是python，一个是pywin32。首先，在http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi 下载python的安装文件（python的首页网址经常被墙，建议直接通过该链接下载），然后在http://jaist.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win32-py2.7.exe  下载pywin32。需要注意的是，R插件只能和python2.7或者python3.1配合使用，本文采用了2.7版本，而pywin32有多个版本和python配合，此处一定要下载针对python2.7的pywin32,所以建议直接点击上面的两个链接下载，以免出错。 （3）为R安装vimcom插件 VIM的R插件除去要安装（2）中提到的python和pywin32之外，还需要在R中安装并启用vimcom插件才能真正工作。启动R，输入： install.packages("vimcom") 然后按照提示选择镜像后安装vimcom插件。安装完成后，点击顶部的“程序包->加载程序包”菜单，在弹出的对话框里选择“vimcom”，启用vimcom插件。 （4）R插件的使用 R插件成功安装后，只有在打开或新建扩展名为R的文件时，才能被激活。所以，在VIM中新建或者打开一个R文件时，会看到VIM的菜单中会多出一个名为R的菜单，工具栏上也会多出几个用于和R通讯的图标。比如，选择R菜单中的启动R，就可以在Windows中直接启动RGUI环境,R菜单还有很多项，大家可以参看菜单上提示的快捷键，在VIM的非编辑状态下，输入对应的快捷键组合启用对应的功能。其实，大部分VIM的使用者都是键盘控，比较习惯用键盘组合。常用的几个如下所示： \rf           ---启动R \rq          ---退出R \l              ---发送当前行到R中执行（注意，是小写的L,即Line的首字母) \ae           ---发送这个文件的源程序到R中执行 值得注意的是，由于对文件编码处理不同，利用\ae发送整个文件源码到R时，不要使用中文的文件名，否则在R中会出现无法打开文件的错误。 成功安装R插件后的运行截图，供参考：

• 1
点赞
• 0
评论
• 1
收藏
• 一键三连
• 扫一扫，分享海报

09-20 1万+
02-27 147

10-10 55
11-18 3万+
02-22 1万+
02-16 1万+
01-03 9304
11-18 8814
11-18 6166
09-18 5434
11-18 4412
01-11 3379