6

I have a file with the following content:

001

Now if I start a macro (qq), yank this line (Y), paste it (p), increase the number by four (4Ctrlaa), end the macro (q), and execute this macro nine times (9@q), then I end up with following:

001
005
011
015
021
025
031
035
041
045
051

How does this work? I mean why is the third number six (001 + 005) digits larger than second number? Or fifth number six digits larger than fourth number, etc.?

1

1 Answer 1

10

If the number starts with a 0 it's interpreted as an octal number (base-8, instead of base-10). Vim also recognises hexadecimal numbers (base-16) if it starts with 0x and binary numbers (base-2) if it starts with 0b.

You can use the 'nrformats' setting to control which numbers Vim recognises; IMHO a value of bin,hex makes the most sense, as it's not easy to confuse a hex or binary in those formats with a regular base-10 number.

Also see the paragraphs below :help v_g_CTRL-X (no direct help tag).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.