Julia REPL Keybindings, Shortcut Keys Clarification

I am trying to understand all the standard keybindings in the Julia REPL. There are some keys I don’t understand and I don’t understand what to search to understand them.

What I do know

If any of this is incorrect, please correct it.

  • ^ is Ctrl
  • meta- is Alt on WIndows, Alt/Option on Mac, Alt on Linux
  • meta-< is actually meta+shift+<. The shift is implied (this is weird because it isn’t implied with other key bindings. for example ^K is Ctrl+k and not Ctrl+Shift+K).

What I don’t know

  1. I can’t seem to make this following work in Julia REPL in Window Terminal or VS Code Terminal.
  • ^-Space Set the “mark” in the editing region (and de-activate the region if it’s active)
  • ^-Space ^-Space Set the “mark” in the editing region and make the region “active”, i.e. highlighted
  1. What is the kill ring? How do I work with it?
  • meta-w Copy the current region in the kill ring
  • meta-W “Kill” the current region, placing the text in the kill ring
  • ^K “Kill” to end of line, placing the text in the kill ring
  • ^Y “Yank” insert the text from the kill ring
  • meta-y Replace a previously yanked text with an older entry from the kill ring

A bit of history:

AFAICS, a lot of these concepts and terminology have been introduced by software from the GNU project (such as Emacs or Readline) very early, back when terms like “copy” or “paste” did not really exist, and keyboards were not standardized like they are today.

Although CUA is probably nowadays the major source of inspiration for most user interface designs (especially key bindings in GUIs), such Emacs-based key-bindings remain widely used in a lot of terminal-based UIs.

All this (not so interesting) discussion to get to one (potentially interesting) point: you might be able to find more detailed information about all this in any source of documentation related to Emacs.

All this looks correct. As you know, a binding like meta-w will be triggered when pressing simultaneously the Alt and w keys. But note that it should also be triggered when pressing Esc followed by w.

meta-< should mean Alt (or Option) in conjunction with whatever key-chord produces the less-than symbol (<). With an English QWERTY keyboard layout, this might be Alt+Shift+, (therefore the implied Shift key). But on my French AZERTY layout, this is simply Alt+<.

You’re right that there is some inconsistency in the way letter keys are denoted. Extracting some examples from the list you already mentioned:

  • meta-w refers to Alt+w
  • meta-W refers to Alt+Shift+w (implied Shift in order to get the upper-case W)
  • meta-F: this should probably rather be meta-f because it refers to Alt+f

I think bindings such as ^C or ^K always refer to Ctrl+letter without any implied Shift.
I might be wrong, but I don’t think there are any bindings with Ctrl+Shift+something (and if there were, it would probably be denoted differently).

The “region” is the part of text between the “mark” and the “point”. The “point” is the current position of the cursor; the mark is a position that you set beforehand using this ^-Space key binding. When the region is “active”, the text in it is highlighted, which makes it easier to visually follow what you’re doing. (But even when the region is not active, you can still use all commands which work on the region, like “killing” / “yanking”)

In short,

  • the “kill ring” is like the “clipboard” in the terminology you’re probably used to (except that it can store several things, more on that below)
  • “killing” is like “cutting” (i.e. delete some text but save it in the “kill ring”/“clipboard”)
  • “yanking” is like “pasting” (retrieve some text from the “kill ring”/“clipboard” and insert it)

So Copy/Kill/Yank is more or less like Copy/Cut/Paste. It operates on the current region, as defined by the previously set “mark” and the current “point”. (And keep in mind that it operates whether the region is active or not).
^K is a specific “kill” operation which does not operate on the region, but rather “kills” all the text from the “point” to the end of the current line.

A difference between the “kill ring” and the clipboard is that the kill ring saves several entries. When you yank something using ^Y, you retrieve by default the last killed text. But if you want to retrieve some older entry instead, you can then press meta-y to yank the second-to-last entry instead. And additional meta-y yank increasingly older entries from the kill-ring, until you get to the one you want and resume normal editing (by pressing anything other than meta-y).

8 Likes

One last thing to keep in mind: the terminal itself (Windows Terminal or VS Code) might very well choose to react to any binding (doing whatever it wants) instead of forwarding it to the Julia REPL running inside it. I don’t use VS Code to much, but I think this happens at least for ^K, which has a default meaning in VS code.

2 Likes

@ffevotte, thank you for your reply! I learned about emacs keybindings and markdown <kbd> tags. Thank you!

Another thing that should be told new users, in my view, is that pressing CTRL+S blocks all output in the REPL until you press CTRL+Q. This is deeply counterintuitive, and typing CTRL+S to save a file is something that may be deep ingrained in muscle memory.

I am not sure it’s the Julia REPL doing that — it may just be terminal flow control. Most terminal emulators allow you do disable it.

Yes this is is unix thing (terminal discipline), see man stty on linux. ^S stands for “Stop output” (from scrolling through the terminal) and ^Q for “Qlear the stopping output”( resume sprinting and scrolling). On Windows I am not sure where/how it is implemented, in mintty most surely, in WindowsTerminal have to check?

Well, it happens in Juno on my machine (JuliaPro on Ubuntu), at least. I am not sure which part of the software stack is responsible for that, but does it matter? It is information that may trip up a new user, because it conflicts with a commonly-used CUA shortcut, and personally I think it should be documented.