1- *vim9.txt* For Vim version 9.1. Last change: 2025 Mar 06
1+ *vim9.txt* For Vim version 9.1. Last change: 2025 Mar 23
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1001,6 +1001,7 @@ empty list and dict is falsy:
10011001 string non-empty
10021002 blob non-empty
10031003 list non-empty (different from JavaScript)
1004+ tuple non-empty (different from JavaScript)
10041005 dictionary non-empty (different from JavaScript)
10051006 func when there is a function name
10061007 special true or v:true
@@ -1048,6 +1049,7 @@ In Vim9 script one can use the following predefined values: >
10481049 null_function
10491050 null_job
10501051 null_list
1052+ null_tuple
10511053 null_object
10521054 null_partial
10531055 null_string
@@ -1467,22 +1469,49 @@ The following builtin types are supported:
14671469 dict<{type} >
14681470 job
14691471 channel
1472+ tuple<{type} >
1473+ tuple<{type} , {type} , ...>
1474+ tuple<...list<{type} >>
1475+ tuple<{type} , ...list<{type} >>
14701476 func
14711477 func: {type}
14721478 func({type} , ...)
14731479 func({type} , ...): {type}
14741480 void
14751481
1476- Not supported yet:
1477- tuple<a: {type} , b: {type} , ...>
1478-
14791482These types can be used in declarations, but no simple value will actually
14801483have the "void" type. Trying to use a void (e.g. a function without a
14811484return value) results in error *E1031* *E1186* .
14821485
14831486There is no array type, use list<{type} > instead. For a list constant an
14841487efficient implementation is used that avoids allocating a lot of small pieces
14851488of memory.
1489+ *tuple-type*
1490+ A tuple type can be declared in more or less specific ways:
1491+ tuple<number> a tuple with a single item of type | Number |
1492+ tuple<number, string> a tuple with two items of type | Number | and
1493+ | String |
1494+ tuple<number, float, bool> a tuple with three items of type | Number | ,
1495+ | Float | and | Boolean | .
1496+ tuple<...list<number> > a variadic tuple with zero or more items of
1497+ type | Number | .
1498+ tuple<number, ...list<string> > a tuple with an item of type | Number | followed
1499+ by zero or more items of type | String | .
1500+
1501+ Examples: >
1502+ var myTuple: tuple<number> = (20,)
1503+ var myTuple: tuple<number, string> = (30, 'vim')
1504+ var myTuple: tuple<number, float, bool> = (40, 1.1, true)
1505+ var myTuple: tuple<...list<string>> = ('a', 'b', 'c')
1506+ var myTuple: tuple<number, ...list<string>> = (3, 'a', 'b', 'c')
1507+ <
1508+ *variadic-tuple* *E1539*
1509+ A variadic tuple has zero or more items of the same type. The type of a
1510+ variadic tuple must end with a list type. Examples: >
1511+ var myTuple: tuple<...list<number>> = (1, 2, 3)
1512+ var myTuple: tuple<...list<string>> = ('a', 'b', 'c')
1513+ var myTuple: tuple<...list<bool>> = ()
1514+ <
14861515 *vim9-func-declaration* *E1005* *E1007*
14871516A partial and function can be declared in more or less specific ways:
14881517func any kind of function reference, no type
@@ -1707,15 +1736,16 @@ argument type checking: >
17071736 *E1211* *E1217* *E1218* *E1219* *E1220* *E1221*
17081737 *E1222* *E1223* *E1224* *E1225* *E1226* *E1227*
17091738 *E1228* *E1238* *E1250* *E1251* *E1252* *E1256*
1710- *E1297* *E1298* *E1301*
1739+ *E1297* *E1298* *E1301* *E1528* *E1529* *E1530*
1740+ *E1531* *E1534*
17111741Types are checked for most builtin functions to make it easier to spot
17121742mistakes.
17131743
17141744Categories of variables, defaults and null handling ~
17151745 *variable-categories* *null-variables*
17161746There are categories of variables:
17171747 primitive number, float, boolean
1718- container string, blob, list, dict
1748+ container string, blob, list, tuple, dict
17191749 specialized function, job, channel, user-defined-object
17201750
17211751When declaring a variable without an initializer, an explicit type must be
@@ -1845,6 +1875,7 @@ An uninitialized variable is usually equal to null; it depends on its type:
18451875 var s: string s == null
18461876 var b: blob b != null ***
18471877 var l: list<any> l != null ***
1878+ var t: tuple<any> t != null ***
18481879 var d: dict<any> d != null ***
18491880 var f: func f == null
18501881 var j: job j == null
@@ -1855,6 +1886,7 @@ A variable initialized to empty equals null_<type>; but not null:
18551886 var s2: string = "" == null_string != null
18561887 var b2: blob = 0z == null_blob != null
18571888 var l2: list<any> = [] == null_list != null
1889+ var t2: tuple<any> = () == null_tuple != null
18581890 var d2: dict<any> = {} == null_dict != null
18591891
18601892NOTE: the specialized variables, like job, default to null value and have no
0 commit comments