1- *eval.txt* For Vim version 8.1. Last change: 2019 Jan 17
1+ *eval.txt* For Vim version 8.1. Last change: 2019 Jan 24
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -38,7 +38,7 @@ done, the features in this document are not available. See |+eval| and
38381. Variables *variables*
3939
40401.1 Variable types ~
41- *E712*
41+ *E712* *E896* *E897* *E899 *
4242There are nine types of variables:
4343
4444Number A 32 or 64 bit signed number. | expr-number | *Number*
@@ -633,6 +633,9 @@ Blob creation ~
633633
634634A Blob can be created with a | blob-literal | : >
635635 :let b = 0zFF00ED015DAF
636+ Dots can be inserted between bytes (pair of hex characters) for readability,
637+ they don't change the value: >
638+ :let b = 0zFF00.ED01.5DAF
636639
637640 A blob can be read from a file with | readfile() | passing the {type} argument
638641set to "B", for example: >
@@ -659,6 +662,16 @@ is not available it returns -1 or the default value you specify: >
659662 :echo get(myblob, idx, 999)
660663
661664
665+ Blob iteration ~
666+
667+ The | :for | loop executes commands for each byte of a Blob. The loop variable is
668+ set to each byte in the Blob. Example: >
669+ :for byte in 0z112233
670+ : call Doit(byte)
671+ :endfor
672+ This calls Doit() with 0x11, 0x22 and 0x33.
673+
674+
662675Blob concatenation ~
663676
664677Two blobs can be concatenated with the "+" operator: >
@@ -790,8 +803,9 @@ Expression syntax summary, from least to most significant:
790803 etc. As above, append ? for ignoring case, # for
791804 matching case
792805
793- expr5 is expr5 same | List | instance
794- expr5 isnot expr5 different | List | instance
806+ expr5 is expr5 same | List | , | Dictionary | or | Blob | instance
807+ expr5 isnot expr5 different | List | , | Dictionary | or | Blob |
808+ instance
795809
796810| expr5 | expr6
797811 expr6 + expr6 .. number addition, list or blob concatenation
@@ -959,12 +973,12 @@ Dictionary and arguments, use |get()| to get the function name: >
959973 if get(Part1, 'name') == get(Part2, 'name')
960974 " Part1 and Part2 refer to the same function
961975
962- When using "is" or "isnot" with a | List | or a | Dictionary | this checks if the
963- expressions are referring to the same | List | or | Dictionary | instance. A copy
964- of a | List | is different from the original | List | . When using "is" without
965- a | List | or a | Dictionary | it is equivalent to using "equal", using "isnot"
966- equivalent to using "not equal". Except that a different type means the
967- values are different: >
976+ Using "is" or "isnot" with a | List | , | Dictionary | or | Blob | checks whether
977+ the expressions are referring to the same | List | , | Dictionary | or | Blob |
978+ instance. A copy of a | List | is different from the original | List | . When
979+ using "is" without a | List | , | Dictionary | or | Blob | , it is equivalent to
980+ using "equal", using "isnot" equivalent to using "not equal". Except that
981+ a different type means the values are different: >
968982 echo 4 == '4'
969983 1
970984 echo 4 is '4'
@@ -1009,16 +1023,16 @@ can be matched like an ordinary character. Examples:
10091023
10101024expr5 and expr6 *expr5* *expr6*
10111025---------------
1012- expr6 + expr6 .. Number addition or | List | concatenation *expr-+*
1013- expr6 - expr6 .. Number subtraction *expr--*
1014- expr6 . expr6 .. String concatenation *expr-.*
1026+ expr6 + expr6 Number addition, | List | or | Blob | concatenation *expr-+*
1027+ expr6 - expr6 Number subtraction *expr--*
1028+ expr6 . expr6 String concatenation *expr-.*
10151029
10161030For | Lists | only "+" is possible and then both expr6 must be a list. The
10171031result is a new list with the two lists Concatenated.
10181032
1019- expr7 * expr7 .. Number multiplication *expr-star*
1020- expr7 / expr7 .. Number division *expr-/*
1021- expr7 % expr7 .. Number modulo *expr-%*
1033+ expr7 * expr7 Number multiplication *expr-star*
1034+ expr7 / expr7 Number division *expr-/*
1035+ expr7 % expr7 Number modulo *expr-%*
10221036
10231037For all, except ".", Strings are converted to Numbers.
10241038For bitwise operators see | and() | , | or() | and | xor() | .
@@ -3805,8 +3819,8 @@ escape({string}, {chars}) *escape()*
38053819 *eval()*
38063820eval({string} ) Evaluate {string} and return the result. Especially useful to
38073821 turn the result of | string() | back into the original value.
3808- This works for Numbers, Floats, Strings and composites of
3809- them. Also works for | Funcref | s that refer to existing
3822+ This works for Numbers, Floats, Strings, Blobs and composites
3823+ of them. Also works for | Funcref | s that refer to existing
38103824 functions.
38113825
38123826eventhandler() *eventhandler()*
@@ -4118,6 +4132,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
41184132 't' Handle keys as if typed; otherwise they are handled as
41194133 if coming from a mapping. This matters for undo,
41204134 opening folds, etc.
4135+ 'L' Lowlevel input. Only works for Unix or when using the
4136+ GUI. Keys are used as if they were coming from the
4137+ terminal. Other flags are not used. *E980*
41214138 'i' Insert the string instead of appending (see above).
41224139 'x' Execute commands until typeahead is empty. This is
41234140 similar to using ":normal!". You can call feedkeys()
@@ -5700,7 +5717,11 @@ items({dict}) *items()*
57005717 Return a | List | with all the key-value pairs of {dict} . Each
57015718 | List | item is a list with two items: the key of a {dict}
57025719 entry and the value of this entry. The | List | is in arbitrary
5703- order.
5720+ order. Also see | keys() | and | values() | .
5721+ Example: >
5722+ for [key, value] in items(mydict)
5723+ echo key . ': ' . value
5724+ endfor
57045725
57055726 job_getchannel({job} ) *job_getchannel()*
57065727 Get the channel handle that {job} is using.
@@ -5733,6 +5754,10 @@ job_start({command} [, {options}]) *job_start()*
57335754 | :!cmd | this does not wait for the job to finish.
57345755 To start a job in a terminal window see | term_start() | .
57355756
5757+ If the job fails to start then | job_status() | on the returned
5758+ Job object results in "fail" and none of the callbacks will be
5759+ invoked.
5760+
57365761 {command} can be a String. This works best on MS-Windows. On
57375762 Unix it is split up in white-separated parts to be passed to
57385763 execvp(). Arguments in double quotes can contain white space.
@@ -5885,7 +5910,7 @@ json_decode({string}) *json_decode()*
58855910 - A trailing comma in an array and object is ignored, e.g.
58865911 "[1, 2, ]" is the same as "[1, 2]".
58875912 - Integer keys are accepted in objects, e.g. {1:2} is the
5888- same as {'1' :2} .
5913+ same as {"1" :2} .
58895914 - More floating point numbers are recognized, e.g. "1." for
58905915 "1.0", or "001.2" for "1.2". Special floating point values
58915916 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
@@ -5897,6 +5922,8 @@ json_decode({string}) *json_decode()*
58975922 - Control characters U+0000 through U+001F which are not
58985923 escaped in strings are accepted, e.g. " " (tab
58995924 character in string) for "\t".
5925+ - An empty JSON expression or made of only spaces is accepted
5926+ and results in v:none.
59005927 - Backslash in an invalid 2-character sequence escape is
59015928 ignored, e.g. "\a" is decoded as "a".
59025929 - A correct surrogate pair in JSON strings should normally be
@@ -5936,7 +5963,7 @@ json_encode({expr}) *json_encode()*
59365963
59375964keys({dict} ) *keys()*
59385965 Return a | List | with all the keys of {dict} . The | List | is in
5939- arbitrary order.
5966+ arbitrary order. Also see | items() | and | values() | .
59405967
59415968 *len()* *E701*
59425969len({expr} ) The result is a Number, which is the length of the argument.
@@ -8617,13 +8644,14 @@ stridx({haystack}, {needle} [, {start}]) *stridx()*
86178644
86188645 *string()*
86198646string({expr} ) Return {expr} converted to a String. If {expr} is a Number,
8620- Float, String or a composition of them, then the result can be
8621- parsed back with | eval() | .
8647+ Float, String, Blob or a composition of them, then the result
8648+ can be parsed back with | eval() | .
86228649 {expr} type result ~
86238650 String 'string' (single quotes are doubled)
86248651 Number 123
86258652 Float 123.123456 or 1.123456e8
86268653 Funcref function('name' )
8654+ Blob 0z00112233.44556677.8899
86278655 List [item, item]
86288656 Dictionary {key: value, key: value}
86298657
@@ -9778,7 +9806,7 @@ uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
97789806
97799807values({dict} ) *values()*
97809808 Return a | List | with all the values of {dict} . The | List | is
9781- in arbitrary order.
9809+ in arbitrary order. Also see | items() | and | keys() | .
97829810
97839811
97849812virtcol({expr} ) *virtcol()*
@@ -11039,28 +11067,34 @@ This does NOT work: >
1103911067 NOTE: The ":append" and ":insert" commands don't work
1104011068 properly inside a ":while" and ":for" loop.
1104111069
11042- :for {var} in {list } *:for* *E690* *E732*
11070+ :for {var} in {object } *:for* *E690* *E732*
1104311071:endfo[r] *:endfo* *:endfor*
1104411072 Repeat the commands between ":for" and ":endfor" for
11045- each item in {list } . Variable {var} is set to the
11046- value of each item.
11047- When an error is detected for a command inside the
11048- loop, execution continues after the "endfor".
11049- Changing {list } inside the loop affects what items are
11050- used. Make a copy if this is unwanted: >
11073+ each item in {object } . {object} can be a | List | or
11074+ a | Blob | . Variable {var} is set to the value of each
11075+ item. When an error is detected for a command inside
11076+ the loop, execution continues after the "endfor".
11077+ Changing {object } inside the loop affects what items
11078+ are used. Make a copy if this is unwanted: >
1105111079 :for item in copy(mylist)
11052- < When not making a copy, Vim stores a reference to the
11053- next item in the list, before executing the commands
11054- with the current item. Thus the current item can be
11055- removed without effect. Removing any later item means
11056- it will not be found. Thus the following example
11057- works (an inefficient way to make a list empty): >
11080+ <
11081+ When {object} is a | List | and not making a copy, Vim
11082+ stores a reference to the next item in the | List |
11083+ before executing the commands with the current item.
11084+ Thus the current item can be removed without effect.
11085+ Removing any later item means it will not be found.
11086+ Thus the following example works (an inefficient way
11087+ to make a | List | empty): >
1105811088 for item in mylist
1105911089 call remove(mylist, 0)
1106011090 endfor
11061- < Note that reordering the list (e.g., with sort() or
11091+ < Note that reordering the | List | (e.g., with sort() or
1106211092 reverse()) may have unexpected effects.
1106311093
11094+ When {object} is a | Blob | , Vim always makes a copy to
11095+ iterate over. Unlike with | List | , modifying the
11096+ | Blob | does not affect the iteration.
11097+
1106411098:for [{var1} , {var2} , ...] in {listlist}
1106511099:endfo[r]
1106611100 Like ":for" above, but each item in {listlist} must be
0 commit comments