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

发布于 2024-10-24 21:06:51 字数 667 浏览 6 评论 0原文

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

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

我使用的是 Mac。

更新

将以下行添加到接受的答案中以获取 ctrl-{a,e}。可以在 jline2 存储库中找到更大的键绑定文件 GitHub 上的 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

Update2

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

So in the Scala REPL, I can use the ctrl-{p,n,a,e} to do previous-, next-, beginning of- and end of line. However, I'll soon go crazy if I can't use ctrl-d to forward-delete.

Is it possible to achieve this in some way?

I'm using a Mac.

Update

Add the following lines to the accepted answer to get ctrl-{a,e}. A larger keybindings file kan be found in the 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

Update2

I just installed Scala 2.9.0.final and I can confirm that the ctrl-d is now working as it should. It's forward delete unless it's an empty line when it terminates the shell.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单气质女生网名 2024-10-31 21:06:51

这是一个非常小的键绑定属性文件,包括您想要的 ^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 来查看默认值(但它不会反映您实际的键绑定)。

Here's a very minimal keybinding property file, including your desired ^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

Put it in a file, and call scala like this:

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

Or pass it through JAVA_OPTS. You'll have to look up on the Internet what keybindings exist, and try :keybindings from Scala to see what are the defaults (it won't reflect your actual keybindings, though).

枫林﹌晚霞¤ 2024-10-31 21:06:51

在 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 笔记本电脑上,可以通过 Fn + BACKSPACE 访问DELETE

in scala 2.9's REPL you have a new :keybindings command. This reveals:

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

on the macbook laptops, DELETE can be accessed via Fn + BACKSPACE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文