Is there a register that stores last regex used by select command?

s activates the select command, prompting for a regex. I want to use this to test a regex that I will then use elsewhere.

After pressing s, entering a regex string, then confirming with <enter>, did that regex I just typed out get saved to a register? If I press s again, it shows as the last used selection term, but this doesn’t seem to be stored in any of the registers shown by ".

Note that I’m after the regex itself, and not the text it selected.

If I press s, then type a regex, for example, “defn \w+”, then press enter, I would like to paste that regex somewhere using "rp (or whatever that register is).

The s command (like /, <a-k>, and others) uses the search history register "/.

If I type sdefn \w+<ret> then I can press "/p to paste that regex.

Hmm, I thought that might be the case, but attempting to test it doesn’t work for me. Interestingly, when I echo %reg{slash} I see a list of everything I previously searched, including via s, so the search terms appear to be getting saved correctly.

So I guess my problem isn’t using the wrong register, but that any method I use to attempt to paste it inserts nothing, as though the value were a blank string. This includes:

  • "/p
  • i<c-r>/
  • Prepending \ (no-hooks) to the above

Any ideas what might cause this?

I’m finding that other registers seem to have the same problem, or at least : (colon) does.

The register entries appear to be stored with the earliest first, and the first entry is always is an empty one which is what "/p shows. "/<a-p> pastes them all. Would probably be more useful if the order was reversed.

Also, alt paste caused a seg fault for me once when I was testing this but couldn’t replicate… If you happen to see the same behaviour would be nice to know.

"/<a-p>Z<a-space><a-d>z should work. Also I found the behaviour on master is a bit different to the last release. It pastes the first actual entry from the register.

FYI breaking-cleanups branch got the order of entries for history registers reversed recently: Store HistoryRegisters with most recent entry in front · mawww/kakoune@531fc7c · GitHub

1 Like