Mercurial > vim
comparison runtime/doc/vim9.txt @ 24024:ef454a7f485d
Update runtime files.
Commit: https://github.com/vim/vim/commit/9faec4e3d439968e21ad74e917aebb289df8f849
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 27 16:38:07 2021 +0100
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Feb 2021 16:45:04 +0100 |
parents | 54b2aa1f0d42 |
children | 788e10cec9bd |
comparison
equal
deleted
inserted
replaced
24023:9b4821b59aa8 | 24024:ef454a7f485d |
---|---|
1 *vim9.txt* For Vim version 8.2. Last change: 2021 Feb 03 | 1 *vim9.txt* For Vim version 8.2. Last change: 2021 Feb 23 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
277 In Vim9 script `:let` cannot be used. An existing variable is assigned to | 277 In Vim9 script `:let` cannot be used. An existing variable is assigned to |
278 without any command. The same for global, window, tab, buffer and Vim | 278 without any command. The same for global, window, tab, buffer and Vim |
279 variables, because they are not really declared. They can also be deleted | 279 variables, because they are not really declared. They can also be deleted |
280 with `:unlet`. | 280 with `:unlet`. |
281 | 281 |
282 Variables and functions cannot shadow previously defined or imported variables | 282 Variables, functions and function arguments cannot shadow previously defined |
283 and functions. | 283 or imported variables and functions in the same script file. |
284 Variables may shadow Ex commands, rename the variable if needed. | 284 Variables may shadow Ex commands, rename the variable if needed. |
285 | 285 |
286 Global variables and user defined functions must be prefixed with "g:", also | 286 Global variables and user defined functions must be prefixed with "g:", also |
287 at the script level. > | 287 at the script level. > |
288 vim9script | 288 vim9script |
305 this for composite structures that you want to make sure will not be modified. | 305 this for composite structures that you want to make sure will not be modified. |
306 Example: > | 306 Example: > |
307 const myList = [1, 2] | 307 const myList = [1, 2] |
308 myList = [3, 4] # Error! | 308 myList = [3, 4] # Error! |
309 myList[0] = 9 # Error! | 309 myList[0] = 9 # Error! |
310 muList->add(3) # Error! | 310 myList->add(3) # Error! |
311 < *:final* | 311 < *:final* |
312 `:final` is used for making only the variable a constant, the value can be | 312 `:final` is used for making only the variable a constant, the value can be |
313 changed. This is well known from Java. Example: > | 313 changed. This is well known from Java. Example: > |
314 final myList = [1, 2] | 314 final myList = [1, 2] |
315 myList = [3, 4] # Error! | 315 myList = [3, 4] # Error! |
316 myList[0] = 9 # OK | 316 myList[0] = 9 # OK |
317 muList->add(3) # OK | 317 myList->add(3) # OK |
318 | 318 |
319 It is common to write constants as ALL_CAPS, but you don't have to. | 319 It is common to write constants as ALL_CAPS, but you don't have to. |
320 | 320 |
321 The constant only applies to the value itself, not what it refers to. > | 321 The constant only applies to the value itself, not what it refers to. > |
322 final females = ["Mary"] | 322 final females = ["Mary"] |
410 } | 410 } |
411 NOT IMPLEMENTED YET | 411 NOT IMPLEMENTED YET |
412 | 412 |
413 *vim9-curly* | 413 *vim9-curly* |
414 To avoid the "{" of a dictionary literal to be recognized as a statement block | 414 To avoid the "{" of a dictionary literal to be recognized as a statement block |
415 wrap it in parenthesis: > | 415 wrap it in parentheses: > |
416 var Lambda = (arg) => ({key: 42}) | 416 var Lambda = (arg) => ({key: 42}) |
417 | 417 |
418 Also when confused with the start of a command block: > | 418 Also when confused with the start of a command block: > |
419 ({ | 419 ({ |
420 key: value | 420 key: value |
1027 - Using a number other than 0 or 1 where a boolean is expected. *E1023* | 1027 - Using a number other than 0 or 1 where a boolean is expected. *E1023* |
1028 - Using a string value when setting a number options. | 1028 - Using a string value when setting a number options. |
1029 - Using a number where a string is expected. *E1024* | 1029 - Using a number where a string is expected. *E1024* |
1030 | 1030 |
1031 One consequence is that the item type of a list or dict given to map() must | 1031 One consequence is that the item type of a list or dict given to map() must |
1032 not change. This will give an error in compiled code: > | 1032 not change. This will give an error in Vim9 script: > |
1033 map([1, 2, 3], (i, v) => 'item ' .. i) | 1033 map([1, 2, 3], (i, v) => 'item ' .. i) |
1034 E1012: Type mismatch; expected list<number> but got list<string> | 1034 E1012: Type mismatch; expected number but got string |
1035 Instead use |mapnew()|. | 1035 Instead use |mapnew()|. If the item type was determined to be "any" it can |
1036 change to a more specific type. E.g. when a list of mixed types gets changed | |
1037 to a list of numbers. | |
1038 Same for |extend()|, use |extendnew()| instead, and for |flatten()|, use | |
1039 |flattennew()| instead. | |
1036 | 1040 |
1037 ============================================================================== | 1041 ============================================================================== |
1038 | 1042 |
1039 5. Namespace, Import and Export | 1043 5. Namespace, Import and Export |
1040 *vim9script* *vim9-export* *vim9-import* | 1044 *vim9script* *vim9-export* *vim9-import* |
1082 finish | 1086 finish |
1083 endif | 1087 endif |
1084 vim9script | 1088 vim9script |
1085 # Vim9 script commands go here | 1089 # Vim9 script commands go here |
1086 This allows for writing a script that takes advantage of the Vim9 script | 1090 This allows for writing a script that takes advantage of the Vim9 script |
1087 syntax if possible, but will also work on an Vim version without it. | 1091 syntax if possible, but will also work on a Vim version without it. |
1088 | 1092 |
1089 This can only work in two ways: | 1093 This can only work in two ways: |
1090 1. The "if" statement evaluates to false, the commands up to `endif` are | 1094 1. The "if" statement evaluates to false, the commands up to `endif` are |
1091 skipped and `vim9script` is then the first command actually executed. | 1095 skipped and `vim9script` is then the first command actually executed. |
1092 2. The "if" statement evaluates to true, the commands up to `endif` are | 1096 2. The "if" statement evaluates to true, the commands up to `endif` are |