【问题标题】:Is there a way to use ctrl-d as forward delete in Scala's REPL?有没有办法在 Scala 的 REPL 中使用 ctrl-d 作为前向删除?
【发布时间】:2011-03-21 23:12:31
【问题描述】:

所以在 Scala REPL 中,我可以使用 ctrl-{p,n,a,e} 来执行上一行、下一行、行首和行尾。但是,如果我不能使用 ctrl-d 进行转发删除,我很快就会发疯。

有没有可能以某种方式实现这一目标?

我使用的是 Mac。

更新

将以下行添加到接受的答案以获得 ctrl-{a,e}。在 jline2 repo jline2 repo at GitHub 中可以找到更大的键绑定文件。

# CTRL-A: move to the beginning of the line
1=MOVE_TO_BEG

# CTRL-E: move the cursor to the end of the line
5=MOVE_TO_END

更新2

我刚刚安装了 Scala 2.9.0.final,我可以确认 ctrl-d 现在可以正常工作。它是向前删除,除非它在终止 shell 时是一个空行。

【问题讨论】:

    标签: scala read-eval-print-loop


    【解决方案1】:

    这是一个非常小的键绑定属性文件,包括您想要的^D

    # CTRL-B: move to the previous character
    2: PREV_CHAR
    
    # CTRL-D: delete the previous character
    4: DELETE_NEXT_CHAR
    
    # CTRL-F: move to the next character
    6: NEXT_CHAR
    
    # BACKSPACE, CTRL-H: delete the previous character
    # 8 is the ASCII code for backspace and therefor
    # deleting the previous character
    8: DELETE_PREV_CHAR
    
    # TAB, CTRL-I: signal that console completion should be attempted
    9: COMPLETE
    
    # CTRL-J, CTRL-M: newline
    10: NEWLINE
    
    # ENTER: newline
    13: NEWLINE
    
    # CTRL-N: scroll to the next element in the history buffer
    14: NEXT_HISTORY
    
    # CTRL-P: scroll to the previous element in the history buffer
    16: PREV_HISTORY
    
    # CTRL-V: paste the contents of the clipboard (useful for Windows terminal)
    22: PASTE
    
    # DELETE, CTRL-?: delete the previous character
    # 127 is the ASCII code for delete
    127: DELETE_PREV_CHAR
    

    把它放在一个文件中,然后像这样调用scala:

    scala -Djline.keybindings=/path/to/keybindings.properties
    

    或通过JAVA_OPTS 传递。您必须在 Internet 上查找存在哪些键绑定,并尝试来自 Scala 的 :keybindings 以查看默认值是什么(但它不会反映您的实际键绑定)。

    【讨论】:

      【解决方案2】:

      在 scala 2.9 的 REPL 中,您有一个新的 :keybindings 命令。这揭示了:

      scala> :keybindings
      Reading jline properties for default key bindings.
      Accuracy not guaranteed: treat this as a guideline only.
      
        1 CTRL-A: move to the beginning of the line
        2 CTRL-B: move to the previous character
        4 CTRL-D: close out the input stream
        5 CTRL-E: move the cursor to the end of the line
        6 CTRL-F: move to the next character
        7 CTRL-G: abort
        8 BACKSPACE, CTRL-H: delete the previous character 8 is the ASCII code for backspace and therefor deleting the previous character
        9 TAB, CTRL-I: signal that console completion should be attempted
       10 CTRL-J, CTRL-M: newline
       11 CTRL-K: erase the current line
       12 CTRL-L: clear screen
       13 ENTER: newline
       14 CTRL-N: scroll to the next element in the history buffer
       15 CTRL-O: move to the previous word
       16 CTRL-P: scroll to the previous element in the history buffer
       18 CTRL-R: redraw the current line
       21 CTRL-U: delete all the characters before the cursor position
       22 CTRL-V: paste the contents of the clipboard (useful for Windows terminal)
       23 CTRL-W: delete the word directly before the cursor
      127 DELETE, CTRL-?: delete the next character 127 is the ASCII code for delete
      

      在 macbook 笔记本电脑上,DELETE 可以通过 Fn + BACKSPACE 访问。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-02
        • 1970-01-01
        • 2015-11-21
        • 1970-01-01
        相关资源
        最近更新 更多