← Back Home

Increment Decrement Numbers in Vim

  1. vim
  2. TIL

Vim is a text editor that keeps surprising you. The more you learn about vim, there is always more to learn. One of the feature that I keep using and find very interesting is incrementing/decrementing a number in current line. Vim has <ctrl-a> to increment a number and <ctrl-x> to decrement a number. Just go to a line with number in it and hit <ctrl-a>/<ctrl-x> to increment/decrement. But because it is vim, there is definitely more to this command. You can also provide a number to add/subtract using the same command.

Increment a number

<ctrl-a> to increment one time, we can also use 180<ctrl-a> to add 180 to an existng number on line

Decrement a number

<ctrl-x> to decrement one time, we can also use 180<ctrl-x> to subtract 180 from a number on line