word boundaries in irb
Asked Answered
N

3

6

I'm using Terminal on Snow Leopard.

At the command line, if I've typed foo.bar.baz.bang.quuz.quux, when i tap option-B, it moves the cursor backward word by word -- stopping at every period, because it considers a period to be a word boundary. Likewise, option-F moves forward word by word.

In irb (0.9.5, ruby 1.8.7), option-B and -F also have this behavior, but the period is no longer treated as a word boundary, which makes these keyboard shortcuts significantly less useful.

How can I change this?

EDIT: Curiouser and curiouser: On an EC2 instance which has the same irb and ruby versions, the period is treated as a word boundary.

Narcose answered 23/2, 2011 at 22:17 Comment(1)
FYI, Ruby 1.9.2 treats the period as a word boundary.Cheeks
K
1

Could this be of relevance here?
http://jorgebernal.info/2009/11/18/fixing-snow-leopard-ruby-readline/

In any case make sure option-B/F are actually bound to forward and backward-word in your inputrc files, like John pointed out.

Also word boundaries are determined by your locale (see the "locale" command), and more specifically by LC_CTYPE (character classification). I don't think that's the problem here, but you might want to check out and compare your locale settings just in case.

Kahler answered 1/7, 2011 at 15:57 Comment(1)
jorgebernal.info's procedure did it. Thanks! Enjoy the bounty; don't spend it all in one place :)Narcose
M
4

I think this has more to do with the Readline module.

The word break characters can be changed. Run this in your IRB and see what characters is Readline using:

Readline.basic_word_break_characters

Readline is part of the standard ruby library: http://ruby-doc.org/stdlib/libdoc/readline/rdoc/index.html

Mishear answered 18/3, 2011 at 18:50 Comment(2)
Thanks for answering, but changing this value doesn't seem to affect the behavior at all. Also, on one of my EC2 instances, Readline.basic_word_break_characters doesn't contain ., but the word movement commands do stop at periods.Narcose
I'm running into the same problem with Ruby 1.9.3 on OS X Lion (10.7) and tried modifying Readline.basic_word_break_characters, but it made no difference either. Also, just like lawrence, on another machine with ruby 1.8.7, Readline.basic_word_break_characters doesn't contain period, but IRB still breaks on the . character, so I really have no clue what this setting has to do with IRB.Claritaclarity
D
1

Readline also uses the following configuration files:

  • /etc/inputrc
  • ~/.inputrc (or a filename specified by the environment variable INPUTRC)

This can cause different behavior on different machines (but probably not between ruby versions - I guess ruby adds another layer of configuration on top).

Dameron answered 29/6, 2011 at 21:25 Comment(0)
K
1

Could this be of relevance here?
http://jorgebernal.info/2009/11/18/fixing-snow-leopard-ruby-readline/

In any case make sure option-B/F are actually bound to forward and backward-word in your inputrc files, like John pointed out.

Also word boundaries are determined by your locale (see the "locale" command), and more specifically by LC_CTYPE (character classification). I don't think that's the problem here, but you might want to check out and compare your locale settings just in case.

Kahler answered 1/7, 2011 at 15:57 Comment(1)
jorgebernal.info's procedure did it. Thanks! Enjoy the bounty; don't spend it all in one place :)Narcose

© 2022 - 2024 — McMap. All rights reserved.