Is there a way to use ctrl-d as a direct delete in Scala REPL?

So, in Scala REPL, I can use ctrl- {p, n, a, e} to execute the previous, next, beginning and end of a line. However, I am going to be crazy soon if I cannot use ctrl-d to send-delete.

Is there any way to achieve this?

I am using a Mac.

Update

Add the following lines to your accepted answer to get ctrl- {a, e}. A larger key binding file can be found in jline2 repo jline2 repo on 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 ctrl-d now works as it should. It forwards the delete, unless an empty line terminates the shell.

+4
source share
2 answers

Here's a very minimal key binding property file, including the 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 as follows:

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

Or pass it through JAVA_OPTS . You will need to find on the Internet which key combinations exist and try :keybindings from scala to find out what the default values ​​are (they will not reflect your actual key bindings).

+4
source

in scala 2.9 REPL you have a new command: keybindings. It shows:

 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 macbooks, DELETE is available through Fn + BACKSPACE .

+3
source

Source: https://habr.com/ru/post/1344696/


All Articles