Mercurial > vim
comparison runtime/doc/eval.txt @ 15498:e1de20a47fa9 v8.1.0757
patch 8.1.0757: not enough documentation for Blobs
commit https://github.com/vim/vim/commit/d89682477cd01ec60edd6d88093b95b12e180127
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 15 22:51:57 2019 +0100
patch 8.1.0757: not enough documentation for Blobs
Problem: Not enough documentation for Blobs.
Solution: Add a section about Blobs.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 15 Jan 2019 23:00:07 +0100 |
parents | f01eb1aed348 |
children | f0f06837a699 |
comparison
equal
deleted
inserted
replaced
15497:bf6ba67f1a1c | 15498:e1de20a47fa9 |
---|---|
1 *eval.txt* For Vim version 8.1. Last change: 2019 Jan 13 | 1 *eval.txt* For Vim version 8.1. Last change: 2019 Jan 15 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
15 1. Variables |variables| | 15 1. Variables |variables| |
16 1.1 Variable types | 16 1.1 Variable types |
17 1.2 Function references |Funcref| | 17 1.2 Function references |Funcref| |
18 1.3 Lists |Lists| | 18 1.3 Lists |Lists| |
19 1.4 Dictionaries |Dictionaries| | 19 1.4 Dictionaries |Dictionaries| |
20 1.5 More about variables |more-variables| | 20 1.5 Blobs |Blobs| |
21 1.6 More about variables |more-variables| | |
21 2. Expression syntax |expression-syntax| | 22 2. Expression syntax |expression-syntax| |
22 3. Internal variable |internal-variables| | 23 3. Internal variable |internal-variables| |
23 4. Builtin Functions |functions| | 24 4. Builtin Functions |functions| |
24 5. Defining functions |user-functions| | 25 5. Defining functions |user-functions| |
25 6. Curly braces names |curly-braces-names| | 26 6. Curly braces names |curly-braces-names| |
51 | 52 |
52 *E928* | 53 *E928* |
53 String A NUL terminated string of 8-bit unsigned characters (bytes). | 54 String A NUL terminated string of 8-bit unsigned characters (bytes). |
54 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c' | 55 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c' |
55 | 56 |
56 List An ordered sequence of items |List|. | 57 List An ordered sequence of items, see |List| for details. |
57 Example: [1, 2, ['a', 'b']] | 58 Example: [1, 2, ['a', 'b']] |
58 | 59 |
59 Dictionary An associative, unordered array: Each entry has a key and a | 60 Dictionary An associative, unordered array: Each entry has a key and a |
60 value. |Dictionary| | 61 value. |Dictionary| |
61 Example: {'blue': "#0000ff", 'red': "#ff0000"} | 62 Example: {'blue': "#0000ff", 'red': "#ff0000"} |
70 | 71 |
71 Job Used for a job, see |job_start()|. *Job* *Jobs* | 72 Job Used for a job, see |job_start()|. *Job* *Jobs* |
72 | 73 |
73 Channel Used for a channel, see |ch_open()|. *Channel* *Channels* | 74 Channel Used for a channel, see |ch_open()|. *Channel* *Channels* |
74 | 75 |
75 Blob Binary Large Object. Stores any sequence of bytes. *Blob* | 76 Blob Binary Large Object. Stores any sequence of bytes. See |Blob| |
77 for details | |
76 Example: 0zFF00ED015DAF | 78 Example: 0zFF00ED015DAF |
77 0z is an empty Blob. | 79 0z is an empty Blob. |
78 | 80 |
79 The Number and String types are converted automatically, depending on how they | 81 The Number and String types are converted automatically, depending on how they |
80 are used. | 82 are used. |
457 example, to add up all the numbers in a list: > | 459 example, to add up all the numbers in a list: > |
458 :exe 'let sum = ' . join(nrlist, '+') | 460 :exe 'let sum = ' . join(nrlist, '+') |
459 | 461 |
460 | 462 |
461 1.4 Dictionaries ~ | 463 1.4 Dictionaries ~ |
462 *dict* *Dictionaries* *Dictionary* | 464 *dict* *Dict* *Dictionaries* *Dictionary* |
463 A Dictionary is an associative array: Each entry has a key and a value. The | 465 A Dictionary is an associative array: Each entry has a key and a value. The |
464 entry can be located with the key. The entries are stored without a specific | 466 entry can be located with the key. The entries are stored without a specific |
465 ordering. | 467 ordering. |
466 | 468 |
467 | 469 |
619 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict | 621 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict |
620 :let s = string(dict) " String representation of dict | 622 :let s = string(dict) " String representation of dict |
621 :call map(dict, '">> " . v:val') " prepend ">> " to each item | 623 :call map(dict, '">> " . v:val') " prepend ">> " to each item |
622 | 624 |
623 | 625 |
624 1.5 More about variables ~ | 626 1.5 Blobs ~ |
627 *blob* *Blob* *Blobs* *E978* | |
628 A Blob mostly behaves like a |List| of numbers, where the numbers have an | |
629 8-bit value, from 0 to 255. | |
630 | |
631 | |
632 Blob creation ~ | |
633 | |
634 A Blob can be created with a |blob-literal|: > | |
635 :let b = 0zFF00ED015DAF | |
636 | |
637 A blob can be read from a file with |readfile()| passing the {type} argument | |
638 set to "B", for example: > | |
639 :let b = readfile('image.png', 'B') | |
640 | |
641 A blob can be read from a channel with the |ch_readblob()| function. | |
642 | |
643 | |
644 Blob index ~ | |
645 *blob-index* *E979* | |
646 A byte in the Blob can be accessed by putting the index in square brackets | |
647 after the Blob. Indexes are zero-based, thus the first byte has index zero. > | |
648 :let myblob = 0z00112233 | |
649 :let byte = myblob[0] " get the first byte: 0x00 | |
650 :let byte = myblob[2] " get the third byte: 0x22 | |
651 | |
652 A negative index is counted from the end. Index -1 refers to the last byte in | |
653 the Blob, -2 to the last but one byte, etc. > | |
654 :let last = myblob[-1] " get the last byte: 0x33 | |
655 | |
656 To avoid an error for an invalid index use the |get()| function. When an item | |
657 is not available it returns -1 or the default value you specify: > | |
658 :echo get(myblob, idx) | |
659 :echo get(myblob, idx, 999) | |
660 | |
661 | |
662 Blob concatenation ~ | |
663 | |
664 Two blobs can be concatenated with the "+" operator: > | |
665 :let longblob = myblob + 0z4455 | |
666 :let myblob += 0z6677 | |
667 | |
668 To change a blob in-place see |blob-modification| below. | |
669 | |
670 | |
671 Part of a blob ~ | |
672 | |
673 A part of the Blob can be obtained by specifying the first and last index, | |
674 separated by a colon in square brackets: > | |
675 :let myblob = 0z00112233 | |
676 :let shortblob = myblob[2:-1] " get 0z2233 | |
677 | |
678 Omitting the first index is similar to zero. Omitting the last index is | |
679 similar to -1. > | |
680 :let endblob = myblob[2:] " from item 2 to the end: 0z2233 | |
681 :let shortblob = myblob[2:2] " Blob with one byte: 0z22 | |
682 :let otherblob = myblob[:] " make a copy of the Blob | |
683 | |
684 If the first index is beyond the last byte of the Blob or the second byte is | |
685 before the first byte, the result is an empty list. There is no error | |
686 message. | |
687 | |
688 If the second index is equal to or greater than the length of the list the | |
689 length minus one is used: > | |
690 :echo myblob[2:8] " result: 0z2233 | |
691 | |
692 | |
693 Blob modification ~ | |
694 *blob-modification* | |
695 To change a specific byte of a blob use |:let| this way: > | |
696 :let blob[4] = 0x44 | |
697 | |
698 When the index is just one beyond the end of the Blob, it is appended. Any | |
699 higher index is an error. | |
700 | |
701 To change a sequence of bytes the [:] notation can be used: > | |
702 let blob[1:3] = 0z445566 | |
703 The length of the replaced bytes much be exactly the same as the value | |
704 provided. *E972* | |
705 | |
706 To change part of a blob you can specify the first and last byte to be | |
707 modified. The value must at least have the number of bytes in the range: > | |
708 :let blob[3:5] = [3, 4, 5] | |
709 | |
710 You can also use the functions |add()|, |remove()| and |insert()|. | |
711 | |
712 | |
713 Blob identity ~ | |
714 | |
715 Blobs can be compared for equality: > | |
716 if blob == 0z001122 | |
717 And for equal identity: > | |
718 if blob is otherblob | |
719 < *blob-identity* *E977* | |
720 When variable "aa" is a Blob and you assign it to another variable "bb", both | |
721 variables refer to the same Blob. Then the "is" operator returns true. | |
722 | |
723 When making a copy using [:] or |copy()| the values are the same, but the | |
724 identity is different: > | |
725 :let blob = 0z112233 | |
726 :let blob2 = blob | |
727 :echo blob == blob2 | |
728 < 1 > | |
729 :echo blob is blob2 | |
730 < 1 > | |
731 :let blob3 = blob[:] | |
732 :echo blob == blob3 | |
733 < 1 > | |
734 :echo blob is blob3 | |
735 < 0 | |
736 | |
737 Making a copy of a list is done with the |copy()| function. Using [:] also | |
738 works, as explained above. | |
739 | |
740 | |
741 1.6 More about variables ~ | |
625 *more-variables* | 742 *more-variables* |
626 If you need to know the type of a variable or expression, use the |type()| | 743 If you need to know the type of a variable or expression, use the |type()| |
627 function. | 744 function. |
628 | 745 |
629 When the '!' flag is included in the 'viminfo' option, global variables that | 746 When the '!' flag is included in the 'viminfo' option, global variables that |
1165 of 'encoding'. | 1282 of 'encoding'. |
1166 | 1283 |
1167 Note that "\000" and "\x00" force the end of the string. | 1284 Note that "\000" and "\x00" force the end of the string. |
1168 | 1285 |
1169 | 1286 |
1170 blob-literal *blob-literal* *E973* *E977* *E978* | 1287 blob-literal *blob-literal* *E973* |
1171 ------------ | 1288 ------------ |
1172 | 1289 |
1173 Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes. | 1290 Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes. |
1174 The sequence must be an even number of hex characters. Example: > | 1291 The sequence must be an even number of hex characters. Example: > |
1175 :let b = 0zFF00ED015DAF | 1292 :let b = 0zFF00ED015DAF |
2045 | 2162 |
2046 USAGE RESULT DESCRIPTION ~ | 2163 USAGE RESULT DESCRIPTION ~ |
2047 | 2164 |
2048 abs({expr}) Float or Number absolute value of {expr} | 2165 abs({expr}) Float or Number absolute value of {expr} |
2049 acos({expr}) Float arc cosine of {expr} | 2166 acos({expr}) Float arc cosine of {expr} |
2050 add({list}, {item}) List append {item} to |List| {list} | 2167 add({object}, {item}) List/Blob append {item} to {object} |
2051 and({expr}, {expr}) Number bitwise AND | 2168 and({expr}, {expr}) Number bitwise AND |
2052 append({lnum}, {text}) Number append {text} below line {lnum} | 2169 append({lnum}, {text}) Number append {text} below line {lnum} |
2053 appendbufline({expr}, {lnum}, {text}) | 2170 appendbufline({expr}, {lnum}, {text}) |
2054 Number append {text} below line {lnum} | 2171 Number append {text} below line {lnum} |
2055 in buffer {expr} | 2172 in buffer {expr} |
2609 :echo acos(-0.5) | 2726 :echo acos(-0.5) |
2610 < 2.094395 | 2727 < 2.094395 |
2611 {only available when compiled with the |+float| feature} | 2728 {only available when compiled with the |+float| feature} |
2612 | 2729 |
2613 | 2730 |
2614 add({list}, {expr}) *add()* | 2731 add({object}, {expr}) *add()* |
2615 Append the item {expr} to |List| {list}. Returns the | 2732 Append the item {expr} to |List| or |Blob| {object}. Returns |
2616 resulting |List|. Examples: > | 2733 the resulting |List| or |Blob|. Examples: > |
2617 :let alist = add([1, 2, 3], item) | 2734 :let alist = add([1, 2, 3], item) |
2618 :call add(mylist, "woodstock") | 2735 :call add(mylist, "woodstock") |
2619 < Note that when {expr} is a |List| it is appended as a single | 2736 < Note that when {expr} is a |List| it is appended as a single |
2620 item. Use |extend()| to concatenate |Lists|. | 2737 item. Use |extend()| to concatenate |Lists|. |
2738 When {object} is a |Blob| then {expr} must be a number. | |
2621 Use |insert()| to add an item at another position. | 2739 Use |insert()| to add an item at another position. |
2622 | 2740 |
2623 | 2741 |
2624 and({expr}, {expr}) *and()* | 2742 and({expr}, {expr}) *and()* |
2625 Bitwise AND on the two arguments. The arguments are converted | 2743 Bitwise AND on the two arguments. The arguments are converted |
3663 | 3781 |
3664 empty({expr}) *empty()* | 3782 empty({expr}) *empty()* |
3665 Return the Number 1 if {expr} is empty, zero otherwise. | 3783 Return the Number 1 if {expr} is empty, zero otherwise. |
3666 - A |List| or |Dictionary| is empty when it does not have any | 3784 - A |List| or |Dictionary| is empty when it does not have any |
3667 items. | 3785 items. |
3668 - A String is empty when its length is zero. | 3786 - A |String| is empty when its length is zero. |
3669 - A Number and Float is empty when its value is zero. | 3787 - A |Number| and |Float| are empty when their value is zero. |
3670 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not. | 3788 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not. |
3671 - A Job is empty when it failed to start. | 3789 - A |Job| is empty when it failed to start. |
3672 - A Channel is empty when it is closed. | 3790 - A |Channel| is empty when it is closed. |
3791 - A Blob is empty when its length is zero. | |
3673 | 3792 |
3674 For a long |List| this is much faster than comparing the | 3793 For a long |List| this is much faster than comparing the |
3675 length with zero. | 3794 length with zero. |
3676 | 3795 |
3677 escape({string}, {chars}) *escape()* | 3796 escape({string}, {chars}) *escape()* |
4339 |test_garbagecollect_now()|. | 4458 |test_garbagecollect_now()|. |
4340 | 4459 |
4341 get({list}, {idx} [, {default}]) *get()* | 4460 get({list}, {idx} [, {default}]) *get()* |
4342 Get item {idx} from |List| {list}. When this item is not | 4461 Get item {idx} from |List| {list}. When this item is not |
4343 available return {default}. Return zero when {default} is | 4462 available return {default}. Return zero when {default} is |
4463 omitted. | |
4464 get({blob}, {idx} [, {default}]) | |
4465 Get byte {idx} from |Blob| {blob}. When this byte is not | |
4466 available return {default}. Return -1 when {default} is | |
4344 omitted. | 4467 omitted. |
4345 get({dict}, {key} [, {default}]) | 4468 get({dict}, {key} [, {default}]) |
4346 Get item with key {key} from |Dictionary| {dict}. When this | 4469 Get item with key {key} from |Dictionary| {dict}. When this |
4347 item is not available return {default}. Return zero when | 4470 item is not available return {default}. Return zero when |
4348 {default} is omitted. | 4471 {default} is omitted. |