17

I have a series of numbers in Mac Terminal Vim which I am incrementing by pressing CTRL-A. Strangley, when I am at 07, the number skips up to 010 instead of 08. I just tried MacVim and had the same behavior occur. Does anyone know why?

Note: Both Vim's work perfectly for 7.

dwalter
  • 7,258
  • 1
  • 32
  • 34
ovatsug25
  • 7,786
  • 7
  • 34
  • 48

2 Answers2

46

If you don't want to increment numbers in octal notation, :set nrformats-=octal.

Dan Fitch
  • 2,480
  • 2
  • 23
  • 39
15

Because a leading zero is a widely used notation for octal, in which the number that comes after 7 is 10. According to Wikipedia, “a prefix 0 is used in the C programming language, Python, Perl, the Unix shell bash, and other languages to specify octal numbers”.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281