vi key bindings in R

November 28th, 2007

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!!

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

One Response to “vi key bindings in R”

  1. On February 1st, 2008 at 8:23 am
    David Tellet wrote:

    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

Leave a Reply