helix icon indicating copy to clipboard operation
helix copied to clipboard

Multiple selection increment

Open MGlolenstine opened this issue 2 years ago • 7 comments

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

  1. Open a file in helix
  2. Paste the above text into it
  3. Navigate to 15, press e and C few times to select all 15s.
  4. Press C-a, which increments numbers.
  5. This results in all numbers becoming 16s and not being incremented from 16-19 as expected.
  6. Same happens for decrements.

Helix log

Helix log is empty.

Platform

Linux

Terminal Emulator

Kitty

Helix Version

helix 22.08.1

MGlolenstine avatar Sep 20 '22 08:09 MGlolenstine

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.

CptPotato avatar Sep 20 '22 09:09 CptPotato

Interesting. I thought it would be the same way as it is with Vim. g <C-a>

MGlolenstine avatar Sep 20 '22 10:09 MGlolenstine

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.

Omnikar avatar Sep 21 '22 01:09 Omnikar

Yeah as far as I know this is expected behavior. This could definitely be a new command though.

dead10ck avatar Sep 21 '22 03:09 dead10ck

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 avatar Sep 21 '22 04:09 MGlolenstine

@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> : image 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.

olafmustafar avatar Sep 22 '22 13:09 olafmustafar

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.

Bruce-Hopkins avatar Oct 22 '22 10:10 Bruce-Hopkins

Resolved by #4418. This is the behavior when the register is #, so #C-a or #C-x would do it.

kirawi avatar Jun 05 '23 14:06 kirawi

Should we specify in the docs that "#C-a/"#C-x has this behaviour?

gabydd avatar Jun 05 '23 14:06 gabydd