]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(doc): Improve :help expr-number
authorDoug Kearns <dougkearns@gmail.com>
Sat, 8 Aug 2026 17:59:27 +0000 (17:59 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 8 Aug 2026 17:59:27 +0000 (17:59 +0000)
closes: #20956

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/eval.txt

index dffeb3859f5b86a11cda2eb5c3da100467fafccc..222dbcc2a2a465e954605245670f55495f4b6da6 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 9.2.  Last change: 2026 May 31
+*eval.txt*     For Vim version 9.2.  Last change: 2026 Aug 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1704,35 +1704,64 @@ number
 number                 number constant                 *expr-number*
 
                        *0x* *hex-number* *0o* *octal-number* *binary-number*
-Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
-and Octal (starting with 0, 0o or 0O).
+Integer numbers can be written in multiple forms:
+
+       {N}             decimal
+       0x{N} or 0X{N}  hexadecimal
+       0o{N} or 0O{N}  octal
+       0{N}            octal (decimal in |scriptversion-4| and |Vim9|)
+       0b{N} or 0B{N}  binary
+
+{N} is a sequence of decimal digits (0-9), hexadecimal digits (0-9, a-f and
+A-F), octal digits (0-7) or binary digits (0 or 1).
+
+Note: A leading "-" or "+" is not part of the number, it is the unary operator
+|expr9| applied to it.
 
 Assuming 64 bit numbers are used (see |v:numbersize|) an unsigned number is
 truncated to 0x7fffffffffffffff or 9223372036854775807.  You can use -1 to get
 0xffffffffffffffff.
 
+In |scriptversion-4| and in |Vim9| script, single quotes may appear between digits
+to improve readability; these are ignored.
+
+Examples:
+       0xDEAD
+       57005
+       0b1101111010101101
+       0o157255
+       0xBE'EF                 |scriptversion-4| and |Vim9|
+       48'879                  |scriptversion-4| and |Vim9|
+       0o137'357               |scriptversion-4| and |Vim9|
+       0b1011'1110'1110'1111   |scriptversion-4| and |Vim9|
+
                                                *floating-point-format*
 Floating point numbers can be written in two forms:
 
-       [-+]{N}.{M}
-       [-+]{N}.{M}[eE][-+]{exp}
+       {N}.{M}
+       {N}.{M}[eE][-+]{exp}
 
-{N} and {M} are numbers.  Both {N} and {M} must be present and can only
-contain digits, except that in |Vim9| script in {N} single quotes between
-digits are ignored.
-[-+] means there is an optional plus or minus sign.
+{N} and {M} are sequences of decimal digits.  In |scriptversion-1| (the default)
+{N} and {M} must be present.  In |scriptversion-2| or higher and in |Vim9| script
+{N} is optional.
 {exp} is the exponent, power of 10.
 Only a decimal point is accepted, not a comma.  No matter what the current
 locale is.
 
+In |scriptversion-4| and in |Vim9| script, single quotes may appear between the
+digits in {N} to improve readability; these are ignored.
+
 Examples:
        123.456
-       +0.0001
+       0.0001
        55.0
-       -0.123
+       0.123
        1.234e03
        1.0E-6
-       -3.1416e+88
+       3.1416e+88
+
+       .123            |scriptversion-2| and |Vim9|
+       123'456.0       |scriptversion-4| and |Vim9|
 
 These are INVALID:
        3.              empty {M}