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

v_CTRL-A/X only increments the first number on each line. #4676

Open
ghost opened this issue Jul 15, 2019 · 5 comments
Open

v_CTRL-A/X only increments the first number on each line. #4676

ghost opened this issue Jul 15, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Jul 15, 2019

I am not sure if this behavior is intended or overlooked. Either case, this is a feature request or bug report, respectively.
It would be nice if all digits in, e.g.

 *    0 ┃ 1 ┃ 2
 *   ━━━╋━━━╋━━━
 *    3 ┃ 4 ┃ 5
 *   ━━━╋━━━╋━━━
 *    6 ┃ 7 ┃ 8

could be incremented simultaneously with v_CTRL-A. Or even make a sequence from:

 *    0 ┃ 0 ┃ 0
 *   ━━━╋━━━╋━━━
 *    0 ┃ 0 ┃ 0
 *   ━━━╋━━━╋━━━
 *    0 ┃ 0 ┃ 0

with v_g_CTRL-A.
Many thanks.

@chrisbra
Copy link
Member

That was not the intention of the visual increment. The initial idea was, to select only those numbers that need to be incremented will be selected and then incremented. Making visual increment increment several numbers within a selected range was not intended.

@ghost
Copy link
Author

ghost commented Jul 15, 2019

Thank you for your prompt reply :-D
Then this is a feature request.
Let me further clarify it. Suppose I have the following code:

std::string words[5];
words[0] = "The";
words[0] = "cat";
words[0] = "on";
words[0] = "the";
words[0] = "tree";

Then selecting from the third line onwards and, while on visual mode, pressing g-CTRL-A produces:

std::string words[5];
words[0] = "The";
words[1] = "cat";
words[2] = "on";
words[3] = "the";
words[4] = "tree";

So far so good.
However, if I have this other code:

vector<int> indexes = {
        0, 3, 4, 9, 12,
        20, 21, 22, 29, 36,
        37, 52, 41, 92, 120 };

and suddenly I realize that the indexing origin I need is 1 rather than 0, then it would be nice, and intuitive I think, to be able to increment by visual select all the numbers and CTRL-A.
Right now, only the first number on each line is incremented, which I find inconvenient and counter-intuitive (because my visual selection covers all the numbers).
Currently, I replace ',' by newlines, increment the numbers, and join them back with J to get the desired result.

@danzollers
Copy link

Do folks have a preference for how this would be implemented? I don't think changing the behavior of v_CTRL-A et. al. is the right approach since it seems reasonable to have both the current behavior and the requested feature in some capacity.

I had two thoughts:

  • Create four new key combinations (to pair with v_CTRL-A, v_CTRL-X, v_g_CTRL-a and v_g_CTRL-X), or
  • Add a new option specifying how many numbers per row to inc/decrement (default to 1 to preserve current behavior)

Are there other approaches that make sense? I'd be happy to explore creating a patch.

@Houl
Copy link
Contributor

Houl commented May 11, 2020

I think it's already a bad thing that precious keys like Ctrl-A and Ctrl-X are wasted to number incrementing. How about a dedicated Ex-command?

@Houl
Copy link
Contributor

Houl commented May 11, 2020

Currently, to increment all numbers:

:%s/\d\+/\=1+submatch(0)/g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants