I am using Mac OS and since latest rails version the delete key does not work anymore.
❯ rails -v
Rails 7.0.4
❯ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
When I hit delete
instead of removing the char and the current cursor position it inserts ^[[3~
.
I could not find out how to fix this. The previous rails version did not have this problem.
CodePudding user response:
Ok, this is a bug in irb that is not yet fixed. Even though 2 PRs exist.
To monkeypatch add this snippet to your .irbrc
class Reline::ANSI
def self.set_default_key_bindings(config)
set_default_key_bindings_comprehensive_list(config)
if Reline::Terminfo.enabled?
set_default_key_bindings_terminfo(config)
end
{
# extended entries of terminfo
[27, 91, 49, 59, 53, 67] => :em_next_word, # Ctrl →, extended entry
[27, 91, 49, 59, 53, 68] => :ed_prev_word, # Ctrl ←, extended entry
[27, 91, 49, 59, 51, 67] => :em_next_word, # Meta →, extended entry
[27, 91, 49, 59, 51, 68] => :ed_prev_word, # Meta ←, extended entry
}.each_pair do |key, func|
config.add_default_key_binding_by_keymap(:emacs, key, func)
config.add_default_key_binding_by_keymap(:vi_insert, key, func)
config.add_default_key_binding_by_keymap(:vi_command, key, func)
end
{
[27, 91, 90] => :completion_journey_up, # S-Tab
}.each_pair do |key, func|
config.add_default_key_binding_by_keymap(:emacs, key, func)
config.add_default_key_binding_by_keymap(:vi_insert, key, func)
end
{
# default bindings
[27, 32] => :em_set_mark, # M-<space>
[24, 24] => :em_exchange_mark, # C-x C-x
}.each_pair do |key, func|
config.add_default_key_binding_by_keymap(:emacs, key, func)
end
end
end
CodePudding user response:
It turns out that this helps:
nano ~/.irbrc
IRB.conf[:USE_READLINE] = true
But then, as a side effect the syntax highlight for the input line is turned off. I live with this as my delete key is more important.