Update runtime files
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
*vim9.txt* For Vim version 8.2. Last change: 2021 Mar 30
|
||||
*vim9.txt* For Vim version 8.2. Last change: 2021 Apr 06
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@ -305,13 +305,21 @@ Variables, functions and function arguments cannot shadow previously defined
|
||||
or imported variables and functions in the same script file.
|
||||
Variables may shadow Ex commands, rename the variable if needed.
|
||||
|
||||
Global variables and user defined functions must be prefixed with "g:", also
|
||||
at the script level. >
|
||||
Global variables must be prefixed with "g:", also at the script level. >
|
||||
vim9script
|
||||
var script_local = 'text'
|
||||
g:global = 'value'
|
||||
var Funcref = g:ThatFunction
|
||||
|
||||
Global functions must be prefixed with "g:" when defining them, but can be
|
||||
called without "g:". >
|
||||
vim9script
|
||||
def g:GlobalFunc(): string
|
||||
return 'text'
|
||||
enddef
|
||||
echo GlobalFunc()
|
||||
The "g:" prefix is not needed for auto-load functions.
|
||||
|
||||
Since `&opt = value` is now assigning a value to option "opt", ":&" cannot be
|
||||
used to repeat a `:substitute` command.
|
||||
|
||||
@ -401,7 +409,7 @@ number of arguments and any return type. The function can be defined later.
|
||||
|
||||
|
||||
Lambda using => instead of -> ~
|
||||
|
||||
*vim9-lambda*
|
||||
In legacy script there can be confusion between using "->" for a method call
|
||||
and for a lambda. Also, when a "{" is found the parser needs to figure out if
|
||||
it is the start of a lambda or a dictionary, which is now more complicated
|
||||
@ -425,12 +433,19 @@ But you can use a backslash to concatenate the lines before parsing: >
|
||||
filter(list, (k,
|
||||
\ v)
|
||||
\ => v > 0)
|
||||
|
||||
< *inline-function*
|
||||
Additionally, a lambda can contain statements in {}: >
|
||||
var Lambda = (arg) => {
|
||||
g:was_called = 'yes'
|
||||
return expression
|
||||
}
|
||||
This can be useful for a timer, for example: >
|
||||
var count = 0
|
||||
var timer = timer_start(500, (_) => {
|
||||
count += 1
|
||||
echom 'Handler called ' .. count
|
||||
}, {repeat: 3})
|
||||
|
||||
|
||||
The ending "}" must be at the start of a line. It can be followed by other
|
||||
characters, e.g.: >
|
||||
@ -836,7 +851,7 @@ Patterns are used like 'magic' is set, unless explicitly overruled.
|
||||
The 'edcompatible' option value is not used.
|
||||
The 'gdefault' option value is not used.
|
||||
|
||||
You may also find this wiki useful. It was written by an early adoptor of
|
||||
You may also find this wiki useful. It was written by an early adopter of
|
||||
Vim9 script: https://github.com/lacygoill/wiki/blob/master/vim/vim9.md
|
||||
|
||||
==============================================================================
|
||||
@ -881,14 +896,14 @@ THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE
|
||||
:enddef End of a function defined with `:def`. It should be on
|
||||
a line by its own.
|
||||
|
||||
You may also find this wiki useful. It was written by an early adoptor of
|
||||
You may also find this wiki useful. It was written by an early adopter of
|
||||
Vim9 script: https://github.com/lacygoill/wiki/blob/master/vim/vim9.md
|
||||
|
||||
If the script the function is defined in is Vim9 script, then script-local
|
||||
variables can be accessed without the "s:" prefix. They must be defined
|
||||
before the function is compiled. If the script the function is defined in is
|
||||
legacy script, then script-local variables must be accessed with the "s:"
|
||||
prefix and they do not need to exist (they can be deleted any time).
|
||||
prefix if they do not exist at the time of compiling.
|
||||
|
||||
*:defc* *:defcompile*
|
||||
:defc[ompile] Compile functions defined in the current script that
|
||||
@ -1073,12 +1088,15 @@ dictionary. If there is a mix of types, the "any" type is used. >
|
||||
['a', 'b', 'c'] list<string>
|
||||
[1, 'x', 3] list<any>
|
||||
|
||||
For script-local variables in Vim9 script the type is checked, also when the
|
||||
variable was declared in a legacy function.
|
||||
|
||||
|
||||
Stricter type checking ~
|
||||
*type-checking*
|
||||
In legacy Vim script, where a number was expected, a string would be
|
||||
automatically converted to a number. This was convenient for an actual number
|
||||
such as "123", but leads to unexpected problems (but no error message) if the
|
||||
such as "123", but leads to unexpected problems (and no error message) if the
|
||||
string doesn't start with a number. Quite often this leads to hard-to-find
|
||||
bugs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user