Number words, not starting from 1

Let’s say I have text

var, var, var

with a selection over each var.

I can use "#p to chage this to var1, var2, var3.

However, is there a good way to get var0, var1, var2 or even var3, var4, var5?

Currently, for small numbers, I end up creating var1, var2, var3, var4, var5 and then deleting the first two, but that requires thinking ahead a bit.

In Vim there is “increase number under cursor” functionality. Is there a way to do something analogous in plain kak, or must I use a plugin (and if so – which one)?

Without searching convoluted solution, I would say the typical one is to leverage an external exec called from %sh{...}. And as interpreted languages are commonly installed you may rather write a little script in your favorite one.

On the other hand, a search gives (untested):
https://github.com/CyborgSquirrel/arithmetic.kak
https://gitlab.com/Screwtapello/kakoune-inc-dec
https://github.com/gustavo-hms/enluarada/tree/main/selections#selections-increment

I’d try some of the plugins @tototest99 suggested. For the pure kakoune solution you could try something like

a<c-r>#<esc>s\d<plus>\z<ret><a-)><space>c0<esc>

As the author of kakoune-inc-dec I think that plugin’s pretty cool!

Probably the most straightforward way to do something like that in Kakoune is to use the shell’s arithmetic feature, combined with the way that Kakoune processes pipes one selection at a time. From your example:

var[1], var[2], var[3]

(where square brackets indicate the selection), you can do:

|printf %s $(( kak_selection - 1 ))

…to get:

var[0], var[1], var[2]

That still requires a bit of boiler-plate, but you could easily map it to <c-x> (and the increment variant to <c-a>).

2 Likes