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

**URL:** <https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075>\
**Category:** Help\
**Created:** [June 13, 2022, 8:07pm UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075 "2022-06-13T20:07:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordan-yee](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jordan-yee/32/592_2.png) [@jordan-yee](https://discuss.kakoune.com/u/jordan-yee)\
**Post date:** [June 13, 2022, 8:07pm UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/1 "2022-06-13T20:07:33Z")

</div>

`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).

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [June 14, 2022, 1:47am UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/2 "2022-06-14T01:47:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jordan-yee](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jordan-yee/32/592_2.png) [@jordan-yee](https://discuss.kakoune.com/u/jordan-yee)\
**Post date:** [June 14, 2022, 5:10pm UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/3 "2022-06-14T17:10:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prion](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/prion/32/404_2.png) [@prion](https://discuss.kakoune.com/u/prion)\
**Post date:** [June 14, 2022, 11:01pm UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/4 "2022-06-14T23:01:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prion](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/prion/32/404_2.png) [@prion](https://discuss.kakoune.com/u/prion)\
**Post date:** [June 14, 2022, 11:13pm UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/5 "2022-06-14T23:13:06Z")

</div>

`"/<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.

---

<div class="post-metadata">

**Author:** ![bravekarma](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@bravekarma](https://discuss.kakoune.com/u/bravekarma)\
**Post date:** [June 15, 2022, 4:47am UTC](https://discuss.kakoune.com/t/is-there-a-register-that-stores-last-regex-used-by-select-command/2075/6 "2022-06-15T04:47:08Z")

</div>

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](https://github.com/mawww/kakoune/commit/531fc7cf60becc84d2ad9a133317569db23efba3)
