Last Updated: February 25, 2016
·
1.785K
· richardkmichael

Ruby, IRB and readline history

If your arrow-keys print an escape sequence in IRB, it could be due to the Ruby Readline module when used with Readline.vi-editing-mode and Readline 6.2.

Consequently, although I prefer vi mode, I've disabled it for now to work around the IRB inconvenience.

I'm using Ruby 1.9.3p392. In Ruby 2.0.0p0 IRB, arrow-keys misbehave slightly differently.

See this Ruby bug.

1.9.3p392 :001 > a = 1
 => 1
1.9.3p392 :003 > [A  # Up arrow pressed here,
                     # line should be "a = 1".

Check if vi editing mode is enabled:

1.9.3p392 :003 > Readline.vi_editing_mode?
 => true

In my case, it was set due to my $HOME/.inputrc file.

set editing-mode vi

Check if Ruby's readline.bundle is compiled against Readline 6.2:

ldd readline.so          # Linux
otool -L readline.bundle # MacOS

Note on MacOS, the Readline module could be compiled against libedit, which is a replacement for libreadline. However, AFAIK, it does not implement vi edit mode. In that case, you might need to change $HOME/.editrc. Google and StackOverflow will help you here.