mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.97k stars 714 forks source link

Support 0 count to select all capture groups #3914

Open alexherbo2 opened 3 years ago

alexherbo2 commented 3 years ago

It can be tedious to select more than one capture.

Example

With the following selection:

file.txt:25:1:Pikachu

Executing

0s(.+?):(\d+):(\d+):(.+?)<ret>

will result:

[file.txt]:[25]:[1]:[Pikachu]

The current way to do is:

s(.+?):(\d+):(\d+):(.+?)<ret>
Z
1s<ret>"fZz
2s<ret>"f<a-Z>az
3s<ret>"f<a-Z>az
"fz

Example in :edit-search.


@lenormf Do not tell me “Why not just S:<ret>?” please :grin:

lenormf commented 3 years ago

It's a good idea, except I think 0 might be confusing since the whole selection technically already is what would be stored under register 0.

So it'd be even better to have a mechanism to select any selection of groups by index — or all. I would intuitively do that in a plugin/command, using the a-z primitive as documented above. :select-matching-groups [0 1 2…]<ret>

occivink commented 3 years ago

Another possibility would be to select all capture groups by default, and to select everything if there are none. Since capture group are rarely used, I think this won't affect interactive usage much, but it's still a breaking change. It does enable a seemingly-simple-but-difficult-to-do operation so it could be interesting.