-*vim9.txt* For Vim version 8.2. Last change: 2021 May 26
+*vim9.txt* For Vim version 8.2. Last change: 2021 Jun 12
VIM REFERENCE MANUAL by Bram Moolenaar
used for the command or inside a `:try` block), does not get a range passed
cannot be a "dict" function, and can always be a closure.
+Later classes will be added, which replaces the "dict function" mechanism.
+For now you will need to pass the dictionary explicitly: >
+ def DictFunc(d: dict<any>, arg: string)
+ echo d[arg]
+ enddef
+ var d = {item: 'value', func: DictFunc}
+ d.func(d, 'item')
+
The argument types and return type need to be specified. The "any" type can
be used, type checking will then be done at runtime, like with legacy
functions.
because of the use of argument types.
To avoid these problems Vim9 script uses a different syntax for a lambda,
-which is similar to Javascript: >
+which is similar to JavaScript: >
var Lambda = (arg) => expression
No line break is allowed in the arguments of a lambda up to and including the
one: 1,
two: 2,
}
-Function call: >
+With a function call: >
var result = Func(
arg1,
arg2
| echo 'match'
| endif
+Note that this means that in heredoc the first line cannot be a bar: >
+ var lines =<< trim END
+ | this doesn't work
+ END
+Either use an empty line at the start or do not use heredoc. Or temporarily
+add the "C" flag to 'cpoptions': >
+ set cpo+=C
+ var lines =<< trim END
+ | this doesn't work
+ END
+ set cpo-=C
+If the heredoc is inside a function 'cpoptions' must be set before :def and
+restored after the :enddef.
+
+In places where line continuation with a backslash is still needed, such as
+splitting up a long Ex command, comments can start with #\ instead of "\: >
+ syn region Text
+ \ start='foo'
+ #\ comment
+ \ end='bar'
+
< *E1050*
To make it possible for the operator at the start of the line to be
-recognized, it is required to put a colon before a range. This will add
-"start" and print: >
+recognized, it is required to put a colon before a range. This example will
+add "start" and print: >
var result = start
+ print
Like this: >
< This does not work: >
echo [1, 2]
[3, 4]
+- In some cases it is difficult for Vim to parse a command, especially when
+ commands are used as an argument to another command, such as `windo`. In
+ those cases the line continuation with a backslash has to be used.
White space ~
export const someValue = ...
export def MyFunc() ...
export class MyClass ...
+ export interface MyClass ...
As this suggests, only constants, variables, `:def` functions and classes can
-be exported. {not implemented yet: export class}
+be exported. {not implemented yet: class, interface}
*E1042*
`:export` can only be used in Vim9 script, at the script level.
For now we'll just make sure classes can be added later.
Thoughts:
-- `class` / `endclass`, everything in one file
-- Class names are always CamelCase
-- Single constructor
+- `class` / `endclass`, the whole class must be in one file
+- Class names are always CamelCase (to avoid a name clash with builtin types)
+- A single constructor called "constructor"
- Single inheritance with `class ThisClass extends BaseClass`
-- `abstract class`
-- `interface` (Abstract class without any implementation)
+- `abstract class` (class with incomplete implementation)
+- `interface` / `endinterface` (abstract class without any implementation)
- `class SomeClass implements SomeInterface`
- Generics for class: `class <Tkey, Tentry>`
- Generics for function: `def <Tkey> GetLast(key: Tkey)`
-Again, much of this is from TypeScript.
+Again, much of this is from TypeScript with a slightly different syntax.
Some things that look like good additions:
- Use a class as an interface (like Dart)
- Extend a class with methods, using an import (like Dart)
+- Mixins
+- For testing: Mock mechanism
An important class that will be provided is "Promise". Since Vim is single
threaded, connecting asynchronous operations is a natural way of allowing
plugins to do their work without blocking the user. It's a uniform way to
invoke callbacks and handle timeouts and errors.
+Some examples: >
+
+ abstract class Person
+ static const prefix = 'xxx'
+ var name: string
+
+ def constructor(name: string)
+ this.name = name;
+ enddef
+
+ def display(): void
+ echo name
+ enddef
+
+ abstract def find(string): Person
+ endclass
+
==============================================================================
9. Rationale *vim9-rationale*
static const unsigned short cmdidxs1[26] =
{
/* a */ 0,
- /* b */ 19,
- /* c */ 43,
- /* d */ 110,
- /* e */ 135,
- /* f */ 162,
- /* g */ 179,
- /* h */ 185,
- /* i */ 194,
- /* j */ 213,
- /* k */ 215,
- /* l */ 220,
- /* m */ 283,
- /* n */ 301,
- /* o */ 321,
- /* p */ 333,
- /* q */ 372,
- /* r */ 375,
- /* s */ 395,
- /* t */ 464,
- /* u */ 510,
- /* v */ 521,
- /* w */ 542,
- /* x */ 556,
- /* y */ 566,
- /* z */ 567
+ /* b */ 20,
+ /* c */ 44,
+ /* d */ 111,
+ /* e */ 136,
+ /* f */ 164,
+ /* g */ 181,
+ /* h */ 187,
+ /* i */ 196,
+ /* j */ 216,
+ /* k */ 218,
+ /* l */ 223,
+ /* m */ 286,
+ /* n */ 304,
+ /* o */ 324,
+ /* p */ 336,
+ /* q */ 375,
+ /* r */ 378,
+ /* s */ 398,
+ /* t */ 468,
+ /* u */ 514,
+ /* v */ 525,
+ /* w */ 546,
+ /* x */ 560,
+ /* y */ 570,
+ /* z */ 571
};
/*
*/
static const unsigned char cmdidxs2[26][26] =
{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
- /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 },
+ /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 8, 16, 0, 17, 0, 0, 0, 0, 0 },
/* b */ { 2, 0, 0, 5, 6, 8, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 0, 14, 0, 0, 0, 0, 23, 0, 0, 0 },
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 38, 41, 47, 57, 59, 60, 61, 0, 63, 0, 66, 0, 0, 0 },
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 },
- /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 21, 0, 22, 0, 0 },
+ /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 22, 0, 23, 0, 0 },
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 },
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0 },
/* h */ { 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- /* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 14, 0, 16, 0, 0, 0, 0, 0 },
+ /* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 15, 0, 17, 0, 0, 0, 0, 0 },
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* l */ { 3, 11, 15, 19, 20, 25, 28, 33, 0, 0, 0, 35, 38, 41, 45, 51, 0, 53, 62, 54, 55, 59, 61, 0, 0, 0 },
/* p */ { 1, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 16, 17, 26, 0, 27, 0, 28, 0 },
/* q */ { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* r */ { 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 19, 0, 0, 0, 0 },
- /* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 63, 64, 0, 65, 0 },
+ /* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 64, 65, 0, 66, 0 },
/* t */ { 2, 0, 19, 0, 24, 26, 0, 27, 0, 28, 0, 29, 33, 36, 38, 39, 0, 40, 42, 0, 43, 0, 0, 0, 45, 0 },
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 12, 15, 0, 0, 0, 0, 18, 0, 19, 0, 0, 0, 0, 0 },
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
-static const int command_count = 584;
+static const int command_count = 588;