Steve Greene's Blog

Adding & Subtracting in Vim

January 26, 2019

Using cntrl + a and cntrl + x in vim normal mode, you can increment or decrement any integer with wrapping. For example, if you had 9 somewhere in your text file, pressing cntrl + a with your cursor over 9 in normal mode will change 9 to 10.
But wait, there’s more.
Vim repetitions allow for any integer to be added to any number by running cntrl + a n times. For example, typing 15 cntrl + a will add 15 to any currently highlighted integer. This is very useful.
But wait, there’s even more.
Vim supports binary and hexidecimal integers with the 0b and 0x prefix. Using vim reptitions, you can automatically add any integer value to any binary or hexidecimal value without having to do any manual conversions. For example, 14 cntrl + a on 0xf will produce 0x1d. How cool is that? Your favorite text editor is also a binary calculator.

Theme originally by mattgraham, forked by me. Site Repo Contact me: [email protected]