vi key bindings in R

I am working on learning R. For those that don’t know, R is a programming language and program a bit similar to Matlab, but is particularly designed for statistics. It is free and open source, and pretty fast and flexible. It has a pretty nice library interface, with lots of user contributed libraries at CRAN (The comprehensive R archive network — modeled after CTAN and CPAN (Tex and Perl respectively)).

On *nix systems, R uses the readline library to give a command history. So I can simply type the up arrow, and find the last command I used. I just discovered that it can also search the command history in the same way as in my BASH shell. Since I like vi, I use vi key bindings in bash. I was pleasantly surprised when R automatically used these as well. I am not sure if it gets them from my .bashrc file or my .inputrc file, since I have vi keymaps set in both.
.bashrc:

set -o vi

.inputrc

set editing-mode vi
set keymap vi

So when I am using R, I can search the history for “foo” by typing:
<esc> /foo

and then use ‘n’ and ‘N’ to go to the next or previous match.

What fun!!

This entry was posted in linux and tagged , , , . Bookmark the permalink.

4 Responses to vi key bindings in R

  1. David Tellet says:

    I’ve been using R for a while now (used the commercial version, S+ in grad school) and find it vastly more useful than most spreadsheets or MathCad, etc. Best use, I find, is in exploratory data analysis when you’re not quite sure how you want to look at or present the data. Steep learning curve, but more power than I will ever use.

    The great thing about R is Sweave – being able to put the R code directly into a LaTeX document, compile in R with Sweave, then compile in LaTeX and you have your complete document with text and data graphic. I still haven’t figured out font encoding in R, but that is a minor issue.

    Great blog, glad I stumbled upon it.

    David

  2. Rosie Khan says:

    i love r&b music becaue it sounds soothing to my ears.~-,

  3. demian says:

    => R gets the information from the .inputrc file.
    Thanx for your post. It helped me to figuer out, how to set vi-like keybindings in R!

  4. Charlie says:

    I must thank you for this! Like yourself, I miss vi keybind whenever it’s not there. And I have been looking around for R.