summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-09-15 14:33:22 +0200
committerBram Moolenaar <Bram@vim.org>2019-09-15 14:33:22 +0200
commit60a8de28d11595f4df0419ece8afa7d6accc9fbd (patch)
tree0dc410fcff779f8f9f7769f775f7e41d924a0da7 /runtime
parent50bf7ce0c9f8c3ede2d1a02c734beba9d5a0504e (diff)
downloadvim-git-60a8de28d11595f4df0419ece8afa7d6accc9fbd.tar.gz
patch 8.1.2035: recognizing octal numbers is confusingv8.1.2035
Problem: Recognizing octal numbers is confusing. Solution: Introduce scriptversion 4: do not use octal and allow for single quote inside numbers.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/eval.txt29
1 files changed, 25 insertions, 4 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 8cb2af1e6..a81731759 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt* For Vim version 8.1. Last change: 2019 Sep 10
+*eval.txt* For Vim version 8.1. Last change: 2019 Sep 15
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -92,7 +92,8 @@ the Number. Examples:
*octal*
Conversion from a String to a Number is done by converting the first digits to
a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
-recognized. If the String doesn't start with digits, the result is zero.
+recognized (NOTE: when using |scriptversion-4| octal is not recognized). If
+the String doesn't start with digits, the result is zero.
Examples:
String "456" --> Number 456 ~
String "6bar" --> Number 6 ~
@@ -2757,7 +2758,8 @@ sqrt({expr}) Float square root of {expr}
str2float({expr}) Float convert String to Float
str2list({expr} [, {utf8}]) List convert each character of {expr} to
ASCII/UTF8 value
-str2nr({expr} [, {base}]) Number convert String to Number
+str2nr({expr} [, {base} [, {quoted}]])
+ Number convert String to Number
strchars({expr} [, {skipcc}]) Number character length of the String {expr}
strcharpart({str}, {start} [, {len}])
String {len} characters of {str} at {start}
@@ -9075,9 +9077,11 @@ str2list({expr} [, {utf8}]) *str2list()*
GetString()->str2list()
-str2nr({expr} [, {base}]) *str2nr()*
+str2nr({expr} [, {base} [, {quoted}]]) *str2nr()*
Convert string {expr} to a number.
{base} is the conversion base, it can be 2, 8, 10 or 16.
+ When {quoted} is present and non-zero then embedded single
+ quotes are ignored, thus "1'000'000" is a million.
When {base} is omitted base 10 is used. This also means that
a leading zero doesn't cause octal conversion to be used, as
@@ -12937,6 +12941,23 @@ instead of failing in mysterious ways.
Test for support with: >
has('vimscript-3')
+<
+ *scriptversion-4* >
+ :scriptversion 4
+< Numbers with a leading zero are not recognized as octal. With the
+ previous version you get: >
+ echo 017 " displays 15
+ echo 018 " displays 18
+< with script version 4: >
+ echo 017 " displays 17
+ echo 018 " displays 18
+< Also, it is possible to use single quotes inside numbers to make them
+ easier to read: >
+ echo 1'000'000
+< The quotes must be surrounded by digits.
+
+ Test for support with: >
+ has('vimscript-4')
==============================================================================
11. No +eval feature *no-eval-feature*