16

I "set editing-mode vi" in my .inputrc on my Mac OS system, which allows vi editing in IRB. When I'm using a RVM Ruby, the IRB sessions don't process this directive.

Does anyone know a solution?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
pixelearth
  • 13,674
  • 10
  • 62
  • 110

6 Answers6

24

Have you got set -o vi set, either at the command-line or in one of your startup scripts? That turns it on for the shell. I have both "set editing-mode vi" and set -o vi and have Vi-like editing in IRB.


EDIT:

Try creating ~/.editrc, put bind -v in it. Snow Leopard has support for editline built in, so that might be what IRB is using.

Try man 5 editrc for more info.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • 2
    Yes I have set -o vi in ~/.bashrc (well actually ~/.bash_profile), and I have vi editing on the command line before going into irb, but then inside irb, it just doesn't seem to process the ~/.inputrc file. This a pretty frustrating setback for me using rvm. I'm sure there is a solution. Someone recommended I try Readline.set_vi_editing (or some such command) but I got the error "not implemented on this machine". Mac Snow Leopard. – pixelearth Jul 10 '11 at 15:23
  • 1
    The ~/.editrc file worked. You're a genious. I love you. Swear to god. Wonder why the system irb used ~/.inputrc and the rvm irb uses ~/.editrc... – pixelearth Jul 17 '11 at 02:19
  • 1
    ~/.editrc worked for me as well, I'm running mountain lion. Thanks! – trumans1 Nov 02 '12 at 02:33
  • this also solve my issue -- however I ran into a problem using it: I had MORE than JUST "bind -v" in my ~/.editrc, which wasn't working. I removed everything else, leaving only "bind -v" and it works fine. – Mike Lyons Apr 11 '13 at 15:39
10

As mentioned before, you can add bind -v in your ~/.editrc.

The problem with this, as you may or may not have noticed is that this removes your ability to use tab completion. If you want to keep tab completion you can add: bind \\t rl_complete to your ~/.editrc.

Nathaniel E.
  • 231
  • 2
  • 5
7

Using RVM-installed Ruby 1.9.3 on Mountain Lion, I was able to get vi key bindings in irb by adding bind -v to ~/.editrc . I installed Ruby 2.0 using RVM on the same system and irb was stuck in emacs mode. Adding set editing-mode vi to ~/.inputrc got vi key bindings working in irb on Ruby 2.0 for me.

jmaxyz
  • 928
  • 1
  • 8
  • 19
  • I had similar experience with MAC OSX El Capitan, using Python3. Adding both bind -v to .editrc, and set editing-mode vi to inputrc worked. – arcseldon Nov 24 '15 at 00:03
3

These days, I'm using rbenv-installed Ruby 2.5 on MacOS Mojave and the way to get vi key bindings in irb is to add set editing-mode vi to ~/.inputrc.

It appears that adding bind -v to ~/.editrc isn't required and doesn't help.

jmaxyz
  • 928
  • 1
  • 8
  • 19
0

I'm on BigSur (11.1) and observe this

  • If using native ruby - edit ~/.editrc to add in 'bind -v'
  • If using RVM built ruby - edit ~/.inputrc and add 'set editing-mode vi'

So you have to do both to make sure. A method does not work for the other

T. Vuong
  • 41
  • 3
0

IRB (interactive Ruby shell) uses the Readline utility for line-editing capabilities.

Readline comes with a set of default keybindings. You can change these in the inputrc file. The location of this file defaults to ~/.inputrc.

When IRB starts up, the inputrc file is read, and the key bindings are set.

To use vim editing mode add the following to your ~/.inputrc

set editing-mode vi
set keymap vi-command

Please consult the documentation for other useful configuration options and where to put them.

lunohodov
  • 5,179
  • 2
  • 25
  • 17