Vim command to increment number digit ONLY at cursor position in a longer number string?
vim
Solution
The increment function takes a leading number like most vim commands. `1000 ctrl+a` would return `2234` like you wanted. If all your numbers are 4 digits numbers then this would work. Or you could use `r2` which replaces the current character under the cursor with a `2`, but this may be too specific.
If you need your script you can record a macro.
`qaa[space][esc]h[ctrl+a]lx`
broken down:
`qa` - start recording a `q` macro and save to register `a`
`a[space][esc]` - add a space after number
`h` - move back to number
`ctrl+a` - add one
`lx` move right and delete space.
You shouldn't need to add a leading space, because as you noticed the `ctrl+a` function acts on the number as a whole and will always add 1.
Problem
I have a few instances where I want to do the following In file: ``` 1234 ``` With the cursor at the 1st digit, I want to use Ctrl-A to increment the digit so that I get ``` 2234 ``` instead of ``` 1235 ``` Are there intrinsic vim commands to do this? Otherwise, should I set up a quick script: - Surround digit with leading and trailing space - Ctrl-A to increment - Delete leading and trailing space Like so, and then map to a key?