Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make search commands respect the register prefix? #5112

Closed
xJonathanLEI opened this issue Dec 10, 2022 · 3 comments · Fixed by #5244
Closed

Make search commands respect the register prefix? #5112

xJonathanLEI opened this issue Dec 10, 2022 · 3 comments · Fixed by #5244
Labels
A-keymap Area: Keymap and keybindings C-discussion Category: Discussion or questions that doesn't represent real issues

Comments

@xJonathanLEI
Copy link
Contributor

Not sure if this should be submitted as a bug or enhancement, so enhancement it is.

Currently serach-related commands do not respect the register prefix and are hard-coded to use /:

  • search
  • rsearch
  • search_next
  • search_prev
  • extend_search_next
  • extend_search_prev
  • search_selection
  • make_search_word_bounded
  • global_search

While search, rsearch, and global_search use a prompt, the register / is still used for completion.

I wonder if this is intentional, given how consistent it is that all search commands discard the register input. Otherwise I'd love to send a PR.

@xJonathanLEI xJonathanLEI added the C-enhancement Category: Improvements label Dec 10, 2022
@pascalkuthe pascalkuthe added C-discussion Category: Discussion or questions that doesn't represent real issues A-keymap Area: Keymap and keybindings and removed C-enhancement Category: Improvements labels Dec 10, 2022
@the-mikedavis
Copy link
Member

search, rsearch and global_search accept selected registers: you can use other registers by selecting them via select_register ("). For example you can yank something with y and then search for it with ""/<ret> ("" selects the " register and then / uses that register for history).

Ideally, search_next, search_prev, extend_search_next, and extend_search_prev would use the same register as the original search if there were one. #4635 might help with that since it adds some state that tracks matches. Allowing them to accept registers isn't ideal since usually you execute these commands multiple times and you would need to select the register each time.

search_selection and make_search_word_bounded are currently hard-coded to / and should probably accept a selected register.

@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Dec 21, 2022

Ah you're right. search, rsearch and global_search do accept register selection. Not sure how I missed that. Sorry. I guess the problem is mostly with search_next etc. not respecting the register originally used to kick start the search then. (Right now if you start a search with a custom register, there's no way to jump to the next occurrence)

Regarding this:

Allowing them to accept registers isn't ideal since usually you execute these commands multiple times and you would need to select the register each time.

What I had in mind was macro scripting, which makes having to press the prefix every time kinda irrelevant. But making these commands use the register used for starting the search is definitely a better approach.

Agree on search_selection and make_search_word_bounded.

To sum it up, I guess the desired changes are:

  • make search_next, search_prev, extend_search_next and extend_search_prev respect the register used to kick start the search in the first place (instead of always using /);
  • make search_selection and make_search_word_bounded accept register selection like search and its friends do.

@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Dec 21, 2022

While working on this, discovered another bug: register selection is unexpectedly discarded when the command keybinding is more than 1 key. For example: "s<SPACE>g does a global search using the default / register instead of the specified s.

Will simply do a key remap for global_search for the sake of this PR to dodge this bug. Will submit a separate issue/PR for the bug.

(so this is actually why I missed the fact that global_search uses the register - I tested the function directly without looking into the source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-keymap Area: Keymap and keybindings C-discussion Category: Discussion or questions that doesn't represent real issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants