有没有办法在Scala的REPL中使用ctrl-d作为前向删除?

时间:2011-03-21 23:12:31

标签: scala read-eval-print-loop

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

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

我正在使用Mac。

更新

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

# 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

UPDATE2

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

2 个答案:

答案 0 :(得分:4)

这是一个非常小的键绑定属性文件,包括您想要的^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传递。您必须在互联网上查找存在哪些键绑定,并尝试从Scala :keybindings查看默认值(它不会反映您实际的键绑定)。

答案 1 :(得分:3)

在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