helix
helix copied to clipboard
Multiple selection increment
Summary
data[0] = 15;
data[0] = 15;
data[0] = 15;
data[0] = 15;
data[0] = 15;
and I'd like to increment them as such.
data[0] = 15;
data[1] = 16;
data[2] = 17;
data[3] = 18;
data[4] = 19;
if I select all of the 15s but the first one and press C-a, it increments them all to 16 and not like I want.
Reproduction Steps
- Open a file in helix
- Paste the above text into it
- Navigate to
15
, presse
andC
few times to select all15
s. - Press
C-a
, which increments numbers. - This results in all numbers becoming
16
s and not being incremented from 16-19 as expected. - Same happens for decrements.
Helix log
Helix log is empty.
Platform
Linux
Terminal Emulator
Kitty
Helix Version
helix 22.08.1
To my knowledge this is actually the intended behavior, not a bug. Increment doesn't produce a range but increments each selected number separately.
Though, I've been in a similar situation where I wanted to generate a range of numbers a few times. For reference, Sublime Text has plugins such as Text Pastry that enable this.
Interesting. I thought it would be the same way as it is with Vim. g <C-a>
One way to achieve the desired behaviour here would be to make sure the top selection is the primary one (using ()
as needed), and alternate C-a
and A-,
until there is 1 selection left. This could also be sped up using a macro.
Yeah as far as I know this is expected behavior. This could definitely be a new command though.
I'd love to work on implementing command like this, but I'll need some hand-holding, as I'm new to the codebase.
@MGlolenstine This is a change you can make in the increment_impl function inside the src/commands.rs to make the increment function behave like vim's g+<C-a> :
I'm not sure if there is a better way to do this since I'm new to this project and also new to rust.
If we are going to implement this there is still the need to define which shortcut we can use.
The PR opened should fix the issue, but it changes the way the increment works. I'm thinking about making this another command, but I don't know what that would look like.
Resolved by #4418. This is the behavior when the register is #
, so #C-a
or #C-x
would do it.
Should we specify in the docs that "#C-a
/"#C-x
has this behaviour?