aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorJason Schulz <jason@schulz.name>2015-12-29 15:17:16 -0800
committerJason Schulz <jason@schulz.name>2016-01-15 18:21:06 -0800
commit7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9 (patch)
treeaaa485d0853be6b46865cf2d87064ec0299f0cde /runtime
parentdddbf9c5fa061cb03d6b6240ac6610b68b9304f5 (diff)
downloadrneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.tar.gz
rneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.tar.bz2
rneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.zip
Add support for binary numbers
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/change.txt19
-rw-r--r--runtime/doc/eval.txt44
2 files changed, 41 insertions, 22 deletions
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 0fa383bc67..42dc84e0de 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -371,8 +371,10 @@ CTRL-X Subtract [count] from the number or alphabetic
character at or after the cursor.
The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
-octal and hexadecimal numbers and alphabetic characters. This depends on the
-'nrformats' option.
+binary/octal/hexadecimal numbers and alphabetic characters. This
+depends on the 'nrformats' option.
+- When 'nrformats' includes "bin", Vim considers numbers starting with '0b' or
+ '0B' as binary.
- When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
to be octal, unless the number includes a '8' or '9'. Other numbers are
decimal and may have a preceding minus sign.
@@ -386,6 +388,10 @@ octal and hexadecimal numbers and alphabetic characters. This depends on the
under or after the cursor. This is useful to make lists with an alphabetic
index.
+For decimals a leading negative sign is considered for incrementing or
+decrementing, for binary and octal and hex values, it won't be considered. To
+ignore the sign Visually select the number before using CTRL-A or CTRL-X.
+
For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible. CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
@@ -397,6 +403,10 @@ octal number.
Note that when 'nrformats' includes "octal", decimal numbers with leading
zeros cause mistakes, because they can be confused with octal numbers.
+Note similarly, when 'nrformats' includes "bin", binary numbers with a leading
+'0x' or '0X' can be interpreted as hexadecimal rather than binary since '0b'
+are valid hexadecimal digits.
+
The CTRL-A command is very useful in a macro. Example: Use the following
steps to make a numbered list.
@@ -1602,7 +1612,7 @@ Vim has a sorting function and a sorting command. The sorting function can be
found here: |sort()|, |uniq()|.
*:sor* *:sort*
-:[range]sor[t][!] [i][u][r][n][x][o] [/{pattern}/]
+:[range]sor[t][!] [i][u][r][n][x][o][b] [/{pattern}/]
Sort lines in [range]. When no range is given all
lines are sorted.
@@ -1622,6 +1632,9 @@ found here: |sort()|, |uniq()|.
With [o] sorting is done on the first octal number in
the line (after or inside a {pattern} match).
+ With [b] sorting is done on the first binary number in
+ the line (after or inside a {pattern} match).
+
With [u] only keep the first of a sequence of
identical lines (ignoring case when [i] is used).
Without this flag, a sequence of identical lines
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index e295772693..3472294483 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -65,14 +65,16 @@ the Number. Examples:
Number 0 --> String "0" ~
Number -1 --> String "-1" ~
*octal*
-Conversion from a String to a Number is done by converting the first digits
-to a number. Hexadecimal "0xf9" and Octal "017" numbers are recognized. If
-the String doesn't start with digits, the result is zero. Examples:
+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.
+Examples:
String "456" --> Number 456 ~
String "6bar" --> Number 6 ~
String "foo" --> Number 0 ~
String "0xf1" --> Number 241 ~
String "0100" --> Number 64 ~
+ String "0b101" --> Number 5 ~
String "-8" --> Number -8 ~
String "+8" --> Number 0 ~
@@ -4912,6 +4914,9 @@ printf({fmt}, {expr1} ...) *printf()*
%c single byte
%d decimal number
%5d decimal number padded with spaces to 5 characters
+ %b binary number
+ %08b binary number padded with zeros to at least 8 characters
+ %B binary number using upper case letters
%x hex number
%04x hex number padded with zeros to at least 4 characters
%X hex number using upper case letters
@@ -4998,20 +5003,19 @@ printf({fmt}, {expr1} ...) *printf()*
The conversion specifiers and their meanings are:
- *printf-d* *printf-o* *printf-x* *printf-X*
- doxX The Number argument is converted to signed decimal
- (d), unsigned octal (o), or unsigned hexadecimal (x
- and X) notation. The letters "abcdef" are used for
- x conversions; the letters "ABCDEF" are used for X
- conversions.
- The precision, if any, gives the minimum number of
- digits that must appear; if the converted value
- requires fewer digits, it is padded on the left with
- zeros.
- In no case does a non-existent or small field width
- cause truncation of a numeric field; if the result of
- a conversion is wider than the field width, the field
- is expanded to contain the conversion result.
+ *printf-d* *printf-b* *printf-B* *printf-o* *printf-x* *printf-X*
+ dbBoxX The Number argument is converted to signed decimal (d),
+ unsigned binary (b and B), unsigned octal (o), or
+ unsigned hexadecimal (x and X) notation. The letters
+ "abcdef" are used for x conversions; the letters
+ "ABCDEF" are used for X conversions. The precision, if
+ any, gives the minimum number of digits that must
+ appear; if the converted value requires fewer digits, it
+ is padded on the left with zeros. In no case does a
+ non-existent or small field width cause truncation of a
+ numeric field; if the result of a conversion is wider
+ than the field width, the field is expanded to contain
+ the conversion result.
*printf-c*
c The Number argument is converted to a byte, and the
@@ -6127,12 +6131,14 @@ str2float( {expr}) *str2float()*
str2nr( {expr} [, {base}]) *str2nr()*
Convert string {expr} to a number.
- {base} is the conversion base, it can be 8, 10 or 16.
+ {base} is the conversion base, it can be 2, 8, 10 or 16.
When {base} is omitted base 10 is used. This also means that
a leading zero doesn't cause octal conversion to be used, as
with the default String to Number conversion.
When {base} is 16 a leading "0x" or "0X" is ignored. With a
- different base the result will be zero.
+ different base the result will be zero. Similarly, when {base}
+ is 8 a leading "0" is ignored, and when {base} is 2 a leading
+ "0b" or "0B" is ignored.
Text after the number is silently ignored.