Mercurial > vim
comparison runtime/doc/vim9.txt @ 27162:b19230a8d40a
Update runtime files
Commit: https://github.com/vim/vim/commit/fd31be29b8220ee1cb0b3460c82f2634ae3cc370
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 16 14:46:06 2022 +0000
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Jan 2022 16:00:06 +0100 |
parents | 15f40772e10a |
children | 5b54f413d132 |
comparison
equal
deleted
inserted
replaced
27161:4ed1558cabe1 | 27162:b19230a8d40a |
---|---|
1 *vim9.txt* For Vim version 8.2. Last change: 2022 Jan 07 | 1 *vim9.txt* For Vim version 8.2. Last change: 2022 Jan 15 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
101 :%s/this/that | 101 :%s/this/that |
102 - Executing a register with "@r" does not work, you can prepend a colon or use | 102 - Executing a register with "@r" does not work, you can prepend a colon or use |
103 `:exe`: > | 103 `:exe`: > |
104 :exe @a | 104 :exe @a |
105 - Unless mentioned specifically, the highest |scriptversion| is used. | 105 - Unless mentioned specifically, the highest |scriptversion| is used. |
106 - When defining an expression mapping, the expression will be evaluated in the | |
107 context of the script where it was defined. | |
106 | 108 |
107 | 109 |
108 Comments starting with # ~ | 110 Comments starting with # ~ |
109 | 111 |
110 In legacy Vim script comments start with double quote. In Vim9 script | 112 In legacy Vim script comments start with double quote. In Vim9 script |
1355 ============================================================================== | 1357 ============================================================================== |
1356 | 1358 |
1357 5. Namespace, Import and Export | 1359 5. Namespace, Import and Export |
1358 *vim9script* *vim9-export* *vim9-import* | 1360 *vim9script* *vim9-export* *vim9-import* |
1359 | 1361 |
1360 A Vim9 script can be written to be imported. This means that everything in | 1362 A Vim9 script can be written to be imported. This means that some items are |
1361 the script is local, except for items that are exported. Those exported | 1363 intentionally exported, made available to other scripts. When the exporting |
1362 items, and only those items, can then be imported in another script. | 1364 script is imported in another script, these exported items can then be used in |
1365 that script. All the other items remain script-local in the exporting script | |
1366 and cannot be accessed by the importing script. | |
1363 | 1367 |
1364 This mechanism exists for writing a script that can be sourced (imported) by | 1368 This mechanism exists for writing a script that can be sourced (imported) by |
1365 other scripts, while making sure these other scripts only have access to what | 1369 other scripts, while making sure these other scripts only have access to what |
1366 you want them to. This also avoids using the global namespace, which has a | 1370 you want them to. This also avoids using the global namespace, which has a |
1367 risc of name collisions. For example when you have two plugins with similar | 1371 risc of name collisions. For example when you have two plugins with similar |
1368 functionality. | 1372 functionality. |
1369 | 1373 |
1370 You can cheat by using the global namespace explicitly. We will assume here | 1374 You can cheat by using the global namespace explicitly. That should be done |
1371 that you don't do that. | 1375 only for things that really are global. |
1372 | 1376 |
1373 | 1377 |
1374 Namespace ~ | 1378 Namespace ~ |
1375 *vim9-namespace* | 1379 *vim9-namespace* |
1376 To recognize a file that can be imported the `vim9script` statement must | 1380 To recognize a file that can be imported the `vim9script` statement must |
1498 or indirectly) imports the current script, then items defined after the | 1502 or indirectly) imports the current script, then items defined after the |
1499 `import` won't be processed yet. Therefore cyclic imports can exist, but may | 1503 `import` won't be processed yet. Therefore cyclic imports can exist, but may |
1500 result in undefined items. | 1504 result in undefined items. |
1501 | 1505 |
1502 | 1506 |
1503 Import in an autoload script ~ | 1507 Importing an autoload script ~ |
1504 *vim9-autoload* | 1508 *vim9-autoload* |
1505 For optimal startup speed, loading scripts should be postponed until they are | 1509 For optimal startup speed, loading scripts should be postponed until they are |
1506 actually needed. Using the autoload mechanism is recommended: | 1510 actually needed. Using the autoload mechanism is recommended: |
1507 | 1511 |
1508 1. In the plugin define user commands, functions and/or mappings that refer to | 1512 1. In the plugin define user commands, functions and/or mappings that refer to |
1532 normally use `import autoload` and not need to specify the prefix. | 1536 normally use `import autoload` and not need to specify the prefix. |
1533 | 1537 |
1534 You can split up the functionality and import other scripts from the | 1538 You can split up the functionality and import other scripts from the |
1535 autoload script as you like. This way you can share code between plugins. | 1539 autoload script as you like. This way you can share code between plugins. |
1536 | 1540 |
1541 For defining a mapping that uses the imported autoload script the special key | |
1542 |<ScriptCmd>| is useful. It allows for a command in a mapping to use the | |
1543 script context of where the mapping was defined. | |
1544 | |
1537 When compiling a `:def` function and a function in an autoload script is | 1545 When compiling a `:def` function and a function in an autoload script is |
1538 encountered, the script is not loaded until the `:def` function is called. | 1546 encountered, the script is not loaded until the `:def` function is called. |
1539 This also means you get any errors only at runtime, since the argument and | 1547 This also means you get any errors only at runtime, since the argument and |
1540 return types are not known yet. | 1548 return types are not known yet. |
1541 | 1549 |
1550 For testing the |test_override()| function can be used to have the | |
1551 `import autoload` load the script right away, so that the items and types can | |
1552 be checked without waiting for them to be actually used: > | |
1553 test_override('autoload', 1) | |
1554 Reset it later with: > | |
1555 test_override('autoload', 0) | |
1556 Or: > | |
1557 test_override('ALL', 0) | |
1558 | |
1542 | 1559 |
1543 Import in legacy Vim script ~ | 1560 Import in legacy Vim script ~ |
1544 | 1561 |
1545 If an `import` statement is used in legacy Vim script, the script-local "s:" | 1562 If an `import` statement is used in legacy Vim script, the script-local "s:" |
1546 namespace will be used for the imported item, even when "s:" is not specified. | 1563 namespace will be used for the imported items, even when "s:" is not |
1564 specified. | |
1547 | 1565 |
1548 | 1566 |
1549 ============================================================================== | 1567 ============================================================================== |
1550 | 1568 |
1551 6. Future work: classes *vim9-classes* | 1569 6. Future work: classes *vim9-classes* |