2

I'm currently reading Learn Vimscript the Hard Way. I did the following experiments as an exercise in the book.

:let &wrap="1.5"
:let &wrap="0.5"
:let &wrap=str2nr("0.5",8)

The first one ran normally, but the second one complains E521: Number required: &wrap = '0.5'. I thought it was the leading zero that cause the error, perhaps it makes Vim regard it as a octal number. So I tested the third hoping it would produce the same error, but it executed normally. What's the reason of these scenarios?

2

Actually, it is treating it as octal number. From :help E521:

Set string or number option to {value}.
For numeric options the value can be given in decimal,
hex (preceded with 0x) or octal (preceded with '0').

Trying without . - let &wrap="05" - Vim won't complain, so it has a problem with the . itself. If you try to run :echo str2nr(".5",8) it also won't fail and print 0. Seems like a bug a bit, and lack of consistency.

  • Thanks! Though I think "0.5" and "05" are different things, in practice nobody would write as such. And only for Vimscript options would such inconsistency occur. – ms huang Nov 17 '16 at 14:44
  • Yes, for us - people - they are different thigs, but Vim seems to treat both as octal number and fails on . – grodzik Nov 17 '16 at 14:47

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.