Kakoune-inc-dec, increment or decrement numbers in the selection

A while ago I wrote a plugin called “kakoune-inc-dec” which allows Vim-style <c-a> and <c-x> to increment or decrement numbers inside the selection. Honestly, I thought I’d already announced it here somewhere, but apparently not.

I’ve recently updated it with the following changes:

  • switched from bc to using shell arithmetic, making the plugin more portable
    • this also means that signed hex and octal numbers are no longer supported, but I don’t think that’s a big loss
  • dropped support for zero-prefixed octal numbers, now only the 0o prefix is supported, which allowed…
  • added support for zero-padded numbers; If you increment “001” you’ll get “002” which is probably what you wanted
  • added online documentation viewable with :doc inc-dec
  • Not necessarily relevant to end-users, but a while ago Kakoune changed the way it updated the selection after piping content to an external process; the new version takes advantage of the new behaviour and makes it much simpler

I think the only place to go from here would be to move a bunch of logic into a helper script written in, say, Python (since it supports arbitrary-precision arithmetic and sophisticated logic), but that would be an order of magnitude more complexity.

10 Likes

Honestly, I thought I’d already announced it here somewhere, but apparently not.

Well, I’ve been using it since April 16 so surely you must’ve annouced it somewhere :slight_smile:

Works great, like many of your plugins by the way!

And the octal change was the right one in my opinion - I hated when vim did that :stuck_out_tongue:

1 Like