How do you read the "Capture Groups" section in trampoline?

I’m having trouble with the section “CAPTURE GROUPS” from trampoline.

Here’s how I interpreted it:

  • press < / >
  • type “(\w+) (\w+)”
  • see that “John Doe” is selected and hit <enter> to confirm
  • press <o> to start a new line in insert mode
  • press ctrl+r 1 to try to paste “John”
  • nothing happens :open_mouth:

Could anyone point me in the right direction?

The trampoline doesn’t mention all the details. If you look at :doc registers integer-registers, it says (emphasis mine):

Registers 1 to 9 hold the grouped sub-matches of the regular expression used to make the last selection.

When you type /(\w+) (\w+)<ret> the selection advances to the next two words; the regex made that selection.

When you type o immediately afterward, Kakoune inserts a line-break, selects it, and enters insert mode. No regex was involved in making that selection, therefore the integer registers are now empty.

Alternatively if you type i or a, the selection doesn’t move so you can still use the integer registers. Likewise, if you type c, the selection’s contents are cleared, but the selection itself doesn’t move, so the integer registers are still available.

Interesting! Thanks for the helpful answer; I had no idea all that was going on under the hood with the o command.

Would you happen to know why the o command is implemented like that? It feels a little unintuitive to me (from a noobie’s perspective).

Insert mode, however you enter it (i, a, o, c, etc.) always inserts the text you type just before the cursor. That’s why those different commands exist: they move the cursor around in different ways before entering insert mode so that the new text winds up where the user wants it.

Specifically for o, the user expects typed text to wind up on a new line. Therefore, it’s implemented by inserting a newline character after the end of the current line and selecting it, before entering insert mode. Text the user types therefore winds up between the two newline characters, and visually appears on a new line.