Mercurial > vim
comparison runtime/doc/vim9.txt @ 31885:cc751d944b7e
Update runtime files.
Commit: https://github.com/vim/vim/commit/be4e01637e71c8d5095c33b9861fd70b41476732
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 2 13:59:48 2023 +0000
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 02 Feb 2023 15:15:06 +0100 |
parents | e5e95e8c78a7 |
children | a9b5ffbc0428 |
comparison
equal
deleted
inserted
replaced
31884:27f905bc04df | 31885:cc751d944b7e |
---|---|
103 `:k` | 103 `:k` |
104 `:mode` | 104 `:mode` |
105 `:open` | 105 `:open` |
106 `:s` with only flags | 106 `:s` with only flags |
107 `:t` | 107 `:t` |
108 `:xit` | 108 `:xit` |
109 - Some commands, especially those used for flow control, cannot be shortened. | 109 - Some commands, especially those used for flow control, cannot be shortened. |
110 E.g., `:throw` cannot be written as `:th`. *vim9-no-shorten* | 110 E.g., `:throw` cannot be written as `:th`. *vim9-no-shorten* |
111 - You cannot use curly-braces names. | 111 - You cannot use curly-braces names. |
112 - A range before a command must be prefixed with a colon: > | 112 - A range before a command must be prefixed with a colon: > |
113 :%s/this/that | 113 :%s/this/that |
263 | 263 |
264 Detail: this is because "Inner" will actually become a function reference to a | 264 Detail: this is because "Inner" will actually become a function reference to a |
265 function with a generated name. | 265 function with a generated name. |
266 | 266 |
267 It is not possible to define a script-local function in a function. You can | 267 It is not possible to define a script-local function in a function. You can |
268 define a local function and assign it to a script-local funcref (it must have | 268 define a local function and assign it to a script-local Funcref (it must have |
269 been declared at the script level). It is possible to define a global | 269 been declared at the script level). It is possible to define a global |
270 function by using the "g:" prefix. | 270 function by using the "g:" prefix. |
271 | 271 |
272 When referring to a function and no "s:" or "g:" prefix is used, Vim will | 272 When referring to a function and no "s:" or "g:" prefix is used, Vim will |
273 search for the function: | 273 search for the function: |
386 ... | 386 ... |
387 } | 387 } |
388 echo temp # Error! | 388 echo temp # Error! |
389 | 389 |
390 This is especially useful in a user command: > | 390 This is especially useful in a user command: > |
391 | |
392 command -range Rename { | 391 command -range Rename { |
393 var save = @a | 392 var save = @a |
394 @a = 'some expression' | 393 @a = 'some expression' |
395 echo 'do something with ' .. @a | 394 echo 'do something with ' .. @a |
396 @a = save | 395 @a = save |
397 } | 396 } |
398 | 397 |
399 And with autocommands: > | 398 And with autocommands: > |
400 | |
401 au BufWritePre *.go { | 399 au BufWritePre *.go { |
402 var save = winsaveview() | 400 var save = winsaveview() |
403 silent! exe ':%! some formatting command' | 401 silent! exe ':%! some formatting command' |
404 winrestview(save) | 402 winrestview(save) |
405 } | 403 } |
744 | echom 'AFTER bar' | 742 | echom 'AFTER bar' |
745 < | 743 < |
746 *E1050* | 744 *E1050* |
747 To make it possible for the operator at the start of the line to be | 745 To make it possible for the operator at the start of the line to be |
748 recognized, it is required to put a colon before a range. This example will | 746 recognized, it is required to put a colon before a range. This example will |
749 add "start" and print: > | 747 add "start" and "print": > |
750 var result = start | 748 var result = start |
751 + print | 749 + print |
752 Like this: > | 750 Like this: > |
753 var result = start + print | 751 var result = start + print |
754 | 752 |
803 4] | 801 4] |
804 < This does not work: > | 802 < This does not work: > |
805 echo [1, 2] | 803 echo [1, 2] |
806 [3, 4] | 804 [3, 4] |
807 - In some cases it is difficult for Vim to parse a command, especially when | 805 - In some cases it is difficult for Vim to parse a command, especially when |
808 commands are used as an argument to another command, such as `windo`. In | 806 commands are used as an argument to another command, such as `:windo`. In |
809 those cases the line continuation with a backslash has to be used. | 807 those cases the line continuation with a backslash has to be used. |
810 | 808 |
811 | 809 |
812 White space ~ | 810 White space ~ |
813 *E1004* *E1068* *E1069* *E1074* *E1127* *E1202* | 811 *E1004* *E1068* *E1069* *E1074* *E1127* *E1202* |
1309 echo range(5)->map((i, _) => flist[i]()) | 1307 echo range(5)->map((i, _) => flist[i]()) |
1310 # Result: [4, 4, 4, 4, 4] | 1308 # Result: [4, 4, 4, 4, 4] |
1311 < *E1271* | 1309 < *E1271* |
1312 A closure must be compiled in the context that it is defined in, so that | 1310 A closure must be compiled in the context that it is defined in, so that |
1313 variables in that context can be found. This mostly happens correctly, except | 1311 variables in that context can be found. This mostly happens correctly, except |
1314 when a function is marked for debugging with `breakadd` after it was compiled. | 1312 when a function is marked for debugging with `:breakadd` after it was compiled. |
1315 Make sure to define the breakpoint before compiling the outer function. | 1313 Make sure to define the breakpoint before compiling the outer function. |
1316 | 1314 |
1317 The "inloop" variable will exist only once, all closures put in the list refer | 1315 The "inloop" variable will exist only once, all closures put in the list refer |
1318 to the same instance, which in the end will have the value 4. This is | 1316 to the same instance, which in the end will have the value 4. This is |
1319 efficient, also when looping many times. If you do want a separate context | 1317 efficient, also when looping many times. If you do want a separate context |
1351 echowin nr | 1349 echowin nr |
1352 }) | 1350 }) |
1353 } | 1351 } |
1354 endfor | 1352 endfor |
1355 | 1353 |
1356 Using `echowindow` is useful in a timer, the messages go into a popup and will | 1354 Using `:echowindow` is useful in a timer, the messages go into a popup and will |
1357 not interfere with what the user is doing when it triggers. | 1355 not interfere with what the user is doing when it triggers. |
1358 | 1356 |
1359 | 1357 |
1360 Converting a function from legacy to Vim9 ~ | 1358 Converting a function from legacy to Vim9 ~ |
1361 *convert_legacy_function_to_vim9* | 1359 *convert_legacy_function_to_vim9* |
1592 ll->extend(['x']) # Error, 'x' is not a number | 1590 ll->extend(['x']) # Error, 'x' is not a number |
1593 That is because the declaration looks like a list of numbers, thus is | 1591 That is because the declaration looks like a list of numbers, thus is |
1594 equivalent to: > | 1592 equivalent to: > |
1595 var ll: list<number> = [1, 2, 3] | 1593 var ll: list<number> = [1, 2, 3] |
1596 If you do want a more permissive list you need to declare the type: > | 1594 If you do want a more permissive list you need to declare the type: > |
1597 var ll: list<any = [1, 2, 3] | 1595 var ll: list<any> = [1, 2, 3] |
1598 ll->extend(['x']) # OK | 1596 ll->extend(['x']) # OK |
1599 | 1597 |
1600 | 1598 |
1601 Stricter type checking ~ | 1599 Stricter type checking ~ |
1602 *type-checking* | 1600 *type-checking* |