Issue #7859 has been updated by Clifford Heath.


David Albert wrote:
> =begin
> I've discovered what I think is a bug in the (({Readline})) module in the standard library.
> =end

vi mode uses an escape character to exit insert mode, enter command mode. ANSI terminals send escape sequences (Escape [ <letter>) for arrow keys.
vi and vim resolve this by using short timeouts; if an escape is received and there is no following [ within 500msec or so, the escape is processed, otherwise it proceeds to resolve an arrow key. The GNU readline library has the same feature: the keyseq-timeout configuration variable, usually set in your ~/.inputrc

Check whether setting this configuration variable fixes your problems. Add a line like this to ~/.inputrc:

    set keyseq-timeout 500

If you want to do further research, the GNU readline code is here: http://ftp.gnu.org/gnu/readline/
Documentation of the inputrc file: http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC12

Ruby's Readline wrapper for the readline library is pretty rudimentary; for example it does not correctly handle escape sequences, nor does it restore single-character input mode after a job-control suspend (^Z followed by fg). This should be entered as a separate bug.

----------------------------------------
Bug #7859: Readline: Incorrect arrow key behavior in vi_editing_mode insert mode with Readline 6.2
https://bugs.ruby-lang.org/issues/7859#change-46994

* Author: David Albert
* Status: Assigned
* Priority: Normal
* Assignee: Kouji Takao
* Category: ext
* Target version: next minor
* ruby -v: 2.0.0-rc2
* Backport: 
----------------------------------------
=begin
I've discovered what I think is a bug in the (({Readline})) module in the standard library. When I am using (({vi_editing_mode})) in insert mode (rather than command mode), I am unable to use the up arrow to go up through history. It seems that I can only go up through history when in command mode. Additionally, pressing the down arrow while in insert mode changes to command mode, which seems odd.

Perhaps this is intended behavior for the (({Readline})) module, but if it is, I would propose changing it. I would expect the up and down arrows to scroll up and down through history in both command mode and insert mode when (({Readline.vi_editing_mode?})) is true. You can find examples of the expected behavior in bash (`((%set -o vi%))` to get into vi mode), the Python REPL, and all other that I can remember using.

I've reproduced this with (({Readline})) 6.2 on Mac OS X 10.8.2 and Ubuntu precise64 with kernel version 3.2.0-37. It is worth noting that on Mac OS X with the EditLine wrapper, the (({Readline})) module works correctly although you must have the proper settings in your .editrc file because (({Readline.vi_editing_mode})) is not implemented.

Here is the code I used to test:

  # readlinetest.rb
  require 'readline'

  trap(:INT) {
    exit 0
  }

  Readline.vi_editing_mode
  puts "Readline::VERSION => #{Readline::VERSION}"

  loop do
    puts Readline.readline(">> ", true)
  end

Example usage:

  $ ruby readlinetest.rb 
  Readline::VERSION => 6.2
  >> 1234
  1234
  >> 

At this point, I would expect that the up arrow would put 1234 after the prompt, but instead nothing happens. Pressing the down arrow is the same as pressing escape and changes (({readline})) into command mode.

Let me know if there's anything else I can provide to help fix this. I tried jumping into the (({Readline})) module myself, but I'm not particularly familiar with how (({readline})) works and wasn't able to make much headway.
=end




-- 
https://bugs.ruby-lang.org/