When I use Merb's built in console, I get tab auto-completion similar to a standard bash prompt. I find this useful and would like to enable it in non-merb IRB sessions. How do I get auto-completion in IRB?
Asked
Active
Viewed 2.0k times
3 Answers
76
Just drop require 'irb/completion'
in your irbrc.
If that doesn't work try bond, http://tagaholic.me/bond/:
require 'bond'; require 'bond/completion'
Bond not only improves irb's completion, http://tagaholic.me/2009/07/22/better-irb-completion-with-bond.html, but also offers an easy dsl for making custom autocompletions.
-
Works great! Minor history bug in Git Bash, but I'm sure it will be fixed. – mcandre Mar 15 '13 at 15:48
-
8Just wanted to add, if you are on Ubuntu, you can create the file ```.irbrc``` in your $HOME directory if it doesn't already exist. – snapfractalpop Aug 19 '14 at 00:40
-
Doesnt work on OSX 10.11.5 with irb version 0.9.6(09/06/30) – Joseph Jul 20 '16 at 12:18
22
This is just repeating the information on Cody Caughlan's comment above so it is easier to find:
either require 'irb/completion'
or add the following to ~/.irbrc
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
IRB.conf[:LOAD_MODULES] << 'irb/completion'
end

John F. Miller
- 26,961
- 10
- 71
- 121
-
"the page above" is a little confusing, as the order of answers can be changed. You may wish to refer to answers by the author of those answers. – Andrew Grimm Sep 07 '09 at 05:51
-
7Why should I add this block to the ibrc if a simple require statement does the same? – maxschlepzig Oct 27 '10 at 17:06
-
@maxschlepzig so you don't have to type `require 'irb/completion'` everytime you use or open irb =) – Viktova Feb 05 '20 at 08:47
-
1@M03, I parsed the sentence 'either require irb/completion or add the following to ~/.irbrc' as "either **add** require irb/completion to ~/.irbrc or add the following to ~/.irbrc'. I haven't used `irb` for years, but I still have a `~/.irbrc` which indeed starts with `require 'irb/completion'` and doesn't include any `LOAD_MODULES` stuff. And with that a history file is loaded and written fine. – maxschlepzig Feb 05 '20 at 22:16
10
This is what worked for me on Mac OS 10.11.5. using rvm. Do the following :
sudo gem install bond
- Create the file
.irbrc
in your home directory.vi ~/.irbrc
Add the following lines in the
.irbrc
filerequire 'bond' Bond.start
Save and close the file
- Open
irb
and usetab
key to autocomplete

Joseph
- 5,793
- 4
- 34
- 41