Wiki

by yszheda

View project onGitHub

Tip 10: Use Counts to Do Simple Arithmetic

Return to the top: <<Practical Vim>>

  • <C-a>: addition on number
  • <C-x>: subtraction on number

Example:

Naive way to change 0 into -180:

A better way using <C-x>:

Vim interprets numerals with a leading zero to be in octal notation rather than in decimal.

For example: <C-a> on 007, you will obtain 010 rather than 008.

To disable this feature, add the following line to your vimrc:

set nrfomats=

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h count
# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h ctrl-a