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
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1001,6 +1001,7 @@ empty list and dict is falsy:
1001
1001
string non-empty
1002
1002
blob non-empty
1003
1003
list non-empty (different from JavaScript)
1004
+ tuple non-empty (different from JavaScript)
1004
1005
dictionary non-empty (different from JavaScript)
1005
1006
func when there is a function name
1006
1007
special true or v:true
@@ -1048,6 +1049,7 @@ In Vim9 script one can use the following predefined values: >
1048
1049
null_function
1049
1050
null_job
1050
1051
null_list
1052
+ null_tuple
1051
1053
null_object
1052
1054
null_partial
1053
1055
null_string
@@ -1467,22 +1469,49 @@ The following builtin types are supported:
1467
1469
dict<{type} >
1468
1470
job
1469
1471
channel
1472
+ tuple<{type} >
1473
+ tuple<{type} , {type} , ...>
1474
+ tuple<...list<{type} >>
1475
+ tuple<{type} , ...list<{type} >>
1470
1476
func
1471
1477
func: {type}
1472
1478
func({type} , ...)
1473
1479
func({type} , ...): {type}
1474
1480
void
1475
1481
1476
- Not supported yet:
1477
- tuple<a: {type} , b: {type} , ...>
1478
-
1479
1482
These types can be used in declarations, but no simple value will actually
1480
1483
have the "void" type. Trying to use a void (e.g. a function without a
1481
1484
return value) results in error *E1031* *E1186* .
1482
1485
1483
1486
There is no array type, use list<{type} > instead. For a list constant an
1484
1487
efficient implementation is used that avoids allocating a lot of small pieces
1485
1488
of 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
+ <
1486
1515
*vim9-func-declaration* *E1005* *E1007*
1487
1516
A partial and function can be declared in more or less specific ways:
1488
1517
func any kind of function reference, no type
@@ -1707,15 +1736,16 @@ argument type checking: >
1707
1736
*E1211* *E1217* *E1218* *E1219* *E1220* *E1221*
1708
1737
*E1222* *E1223* *E1224* *E1225* *E1226* *E1227*
1709
1738
*E1228* *E1238* *E1250* *E1251* *E1252* *E1256*
1710
- *E1297* *E1298* *E1301*
1739
+ *E1297* *E1298* *E1301* *E1528* *E1529* *E1530*
1740
+ *E1531* *E1534*
1711
1741
Types are checked for most builtin functions to make it easier to spot
1712
1742
mistakes.
1713
1743
1714
1744
Categories of variables, defaults and null handling ~
1715
1745
*variable-categories* *null-variables*
1716
1746
There are categories of variables:
1717
1747
primitive number, float, boolean
1718
- container string, blob, list, dict
1748
+ container string, blob, list, tuple, dict
1719
1749
specialized function, job, channel, user-defined-object
1720
1750
1721
1751
When 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:
1845
1875
var s: string s == null
1846
1876
var b: blob b != null ***
1847
1877
var l: list<any> l != null ***
1878
+ var t: tuple<any> t != null ***
1848
1879
var d: dict<any> d != null ***
1849
1880
var f: func f == null
1850
1881
var j: job j == null
@@ -1855,6 +1886,7 @@ A variable initialized to empty equals null_<type>; but not null:
1855
1886
var s2: string = "" == null_string != null
1856
1887
var b2: blob = 0z == null_blob != null
1857
1888
var l2: list<any> = [] == null_list != null
1889
+ var t2: tuple<any> = () == null_tuple != null
1858
1890
var d2: dict<any> = {} == null_dict != null
1859
1891
1860
1892
NOTE: the specialized variables, like job, default to null value and have no
0 commit comments