Having the cursor on a 017 and doing a ctrl-a increases it to 020, when I would have expected 018. Is this a bug (vim 8.0 on Ubuntu 18.04) or why would one want this?

  • 1
    Thanks for the tip, I didn't know about ctrl+A and ctrl+X. – Eric Duminil Apr 12 '20 at 12:25

This is vim expecting 017 to be octal and doing the sensible thing for an octal number (017 = 8+7 = 15; 020 = 2*8 = 16).

To tell vim you don't use octal numbers, set nrformats-=octal. More at :help 'nrformats' and :help CTRL-A.

  • 6
    Since so many people today think this a mistake, it is worth pointing out that vim follows this editing convention because numerous programming languages also do for their numeric constants.. including C, javascript, perl, ruby, and python2. – Mass Apr 11 '20 at 22:38
  • 2
    Also worth noting that defaults.vim disables octal in nrformats, so you'll get that setting correct if you don't have a vimrc file or if you source it explicitly. – filbranden Apr 12 '20 at 5:21
  • @Mass Note that they're trying to deprecate 0-prefixed octal constants in JavaScript. – Mr Lister Apr 12 '20 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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