4

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

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

我正在使用 Mac。

更新

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

# 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 时是空行。

4

2 回答 2

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。您必须在 Internet 上查找存在哪些键绑定,并尝试:keybindings从 Scala 中查看默认值是什么(但它不会反映您的实际键绑定)。

于 2011-03-22T00:43:26.487 回答
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.

于 2011-03-21T23:56:31.580 回答