Mercurial > vim
comparison runtime/doc/eval.txt @ 27459:5825405e4e2c
Update runtime files
Commit: https://github.com/vim/vim/commit/f10911e5db16f1fe6ab519c5d091ad0c1df0d063
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 29 22:20:48 2022 +0000
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 Jan 2022 23:30:04 +0100 |
parents | 3649b5a6b1b6 |
children | 063952f68595 |
comparison
equal
deleted
inserted
replaced
27458:2a7fc102cb91 | 27459:5825405e4e2c |
---|---|
1 *eval.txt* For Vim version 8.2. Last change: 2022 Jan 21 | 1 *eval.txt* For Vim version 8.2. Last change: 2022 Jan 24 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
42 | 42 |
43 ============================================================================== | 43 ============================================================================== |
44 1. Variables *variables* | 44 1. Variables *variables* |
45 | 45 |
46 1.1 Variable types ~ | 46 1.1 Variable types ~ |
47 *E712* *E896* *E897* *E899* | 47 *E712* *E896* *E897* *E899* *E1098* |
48 *E1107* *E1135* *E1138* | |
48 There are ten types of variables: | 49 There are ten types of variables: |
49 | 50 |
50 *Number* *Integer* | 51 *Number* *Integer* |
51 Number A 32 or 64 bit signed number. |expr-number| | 52 Number A 32 or 64 bit signed number. |expr-number| |
52 The number of bits is available in |v:numbersize|. | 53 The number of bits is available in |v:numbersize|. |
178 *no-type-checking* | 179 *no-type-checking* |
179 You will not get an error if you try to change the type of a variable. | 180 You will not get an error if you try to change the type of a variable. |
180 | 181 |
181 | 182 |
182 1.2 Function references ~ | 183 1.2 Function references ~ |
183 *Funcref* *E695* *E718* | 184 *Funcref* *E695* *E718* *E1086* |
184 A Funcref variable is obtained with the |function()| function, the |funcref()| | 185 A Funcref variable is obtained with the |function()| function, the |funcref()| |
185 function or created with the lambda expression |expr-lambda|. It can be used | 186 function or created with the lambda expression |expr-lambda|. It can be used |
186 in an expression in the place of a function name, before the parenthesis | 187 in an expression in the place of a function name, before the parenthesis |
187 around the arguments, to invoke the function it refers to. Example: > | 188 around the arguments, to invoke the function it refers to. Example: > |
188 | 189 |
833 In legacy script it is possible to form a variable name with curly braces, see | 834 In legacy script it is possible to form a variable name with curly braces, see |
834 |curly-braces-names|. | 835 |curly-braces-names|. |
835 | 836 |
836 ============================================================================== | 837 ============================================================================== |
837 2. Expression syntax *expression-syntax* | 838 2. Expression syntax *expression-syntax* |
838 | 839 *E1143* |
839 Expression syntax summary, from least to most significant: | 840 Expression syntax summary, from least to most significant: |
840 | 841 |
841 |expr1| expr2 | 842 |expr1| expr2 |
842 expr2 ? expr1 : expr1 if-then-else | 843 expr2 ? expr1 : expr1 if-then-else |
843 | 844 |
913 "..." indicates that the operations in this level can be concatenated. | 914 "..." indicates that the operations in this level can be concatenated. |
914 Example: > | 915 Example: > |
915 &nu || &list && &shell == "csh" | 916 &nu || &list && &shell == "csh" |
916 | 917 |
917 All expressions within one level are parsed from left to right. | 918 All expressions within one level are parsed from left to right. |
919 | |
920 Expression nesting is limited to 1000 levels deep (300 when build with MSVC) | |
921 to avoid running out of stack and crashing. *E1169* | |
918 | 922 |
919 | 923 |
920 expr1 *expr1* *trinary* *falsy-operator* *??* *E109* | 924 expr1 *expr1* *trinary* *falsy-operator* *??* *E109* |
921 ----- | 925 ----- |
922 | 926 |
1337 | 1341 |
1338 Note that the dot is also used for String concatenation. To avoid confusion | 1342 Note that the dot is also used for String concatenation. To avoid confusion |
1339 always put spaces around the dot for String concatenation. | 1343 always put spaces around the dot for String concatenation. |
1340 | 1344 |
1341 | 1345 |
1342 expr9(expr1, ...) |Funcref| function call | 1346 expr9(expr1, ...) |Funcref| function call *E1085* |
1343 | 1347 |
1344 When expr9 is a |Funcref| type variable, invoke the function it refers to. | 1348 When expr9 is a |Funcref| type variable, invoke the function it refers to. |
1345 | 1349 |
1346 | 1350 |
1347 expr9->name([args]) method call *method* *->* | 1351 expr9->name([args]) method call *method* *->* |
1575 :echo expand("$shell") | 1579 :echo expand("$shell") |
1576 The first one probably doesn't echo anything, the second echoes the $shell | 1580 The first one probably doesn't echo anything, the second echoes the $shell |
1577 variable (if your shell supports it). | 1581 variable (if your shell supports it). |
1578 | 1582 |
1579 | 1583 |
1580 internal variable *expr-variable* *E1015* | 1584 internal variable *expr-variable* *E1015* *E1089* |
1581 ----------------- | 1585 ----------------- |
1582 variable internal variable | 1586 variable internal variable |
1583 See below |internal-variables|. | 1587 See below |internal-variables|. |
1584 | 1588 |
1585 | 1589 |
2707 | 2711 |
2708 To be able to define a function inside an `:execute` | 2712 To be able to define a function inside an `:execute` |
2709 command, use line breaks instead of |:bar|: > | 2713 command, use line breaks instead of |:bar|: > |
2710 :exe "func Foo()\necho 'foo'\nendfunc" | 2714 :exe "func Foo()\necho 'foo'\nendfunc" |
2711 < | 2715 < |
2712 *:delf* *:delfunction* *E131* *E933* | 2716 *:delf* *:delfunction* *E131* *E933* *E1084* |
2713 :delf[unction][!] {name} | 2717 :delf[unction][!] {name} |
2714 Delete function {name}. | 2718 Delete function {name}. |
2715 {name} can also be a |Dictionary| entry that is a | 2719 {name} can also be a |Dictionary| entry that is a |
2716 |Funcref|: > | 2720 |Funcref|: > |
2717 :delfunc dict.init | 2721 :delfunc dict.init |
2724 :retu[rn] [expr] Return from a function. When "[expr]" is given, it is | 2728 :retu[rn] [expr] Return from a function. When "[expr]" is given, it is |
2725 evaluated and returned as the result of the function. | 2729 evaluated and returned as the result of the function. |
2726 If "[expr]" is not given, the number 0 is returned. | 2730 If "[expr]" is not given, the number 0 is returned. |
2727 When a function ends without an explicit ":return", | 2731 When a function ends without an explicit ":return", |
2728 the number 0 is returned. | 2732 the number 0 is returned. |
2729 Note that there is no check for unreachable lines, | 2733 In a :def function *E1095* is given if unreachable |
2730 thus there is no warning if commands follow ":return". | 2734 code follows after the `:return`. |
2735 In legacy script there is no check for unreachable | |
2736 lines, thus there is no warning if commands follow | |
2737 `:return`. | |
2731 | 2738 |
2732 If the ":return" is used after a |:try| but before the | 2739 If the ":return" is used after a |:try| but before the |
2733 matching |:finally| (if present), the commands | 2740 matching |:finally| (if present), the commands |
2734 following the ":finally" up to the matching |:endtry| | 2741 following the ":finally" up to the matching |:endtry| |
2735 are executed first. This process applies to all | 2742 are executed first. This process applies to all |
2744 arguments an argument "..." can be specified, which means that more arguments | 2751 arguments an argument "..." can be specified, which means that more arguments |
2745 may optionally be following. In the function the extra arguments can be used | 2752 may optionally be following. In the function the extra arguments can be used |
2746 as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which | 2753 as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which |
2747 can be 0). "a:000" is set to a |List| that contains these arguments. Note | 2754 can be 0). "a:000" is set to a |List| that contains these arguments. Note |
2748 that "a:1" is the same as "a:000[0]". | 2755 that "a:1" is the same as "a:000[0]". |
2749 *E742* | 2756 *E742* *E1090* |
2750 The a: scope and the variables in it cannot be changed, they are fixed. | 2757 The a: scope and the variables in it cannot be changed, they are fixed. |
2751 However, if a composite type is used, such as |List| or |Dictionary| , you can | 2758 However, if a composite type is used, such as |List| or |Dictionary| , you can |
2752 change their contents. Thus you can pass a |List| to a function and have the | 2759 change their contents. Thus you can pass a |List| to a function and have the |
2753 function add an item to it. If you want to make sure the function cannot | 2760 function add an item to it. If you want to make sure the function cannot |
2754 change a |List| or |Dictionary| use |:lockvar|. | 2761 change a |List| or |Dictionary| use |:lockvar|. |
3052 Set internal variable {var-name} to the result of the | 3059 Set internal variable {var-name} to the result of the |
3053 expression {expr1}. The variable will get the type | 3060 expression {expr1}. The variable will get the type |
3054 from the {expr}. If {var-name} didn't exist yet, it | 3061 from the {expr}. If {var-name} didn't exist yet, it |
3055 is created. | 3062 is created. |
3056 | 3063 |
3057 :let {var-name}[{idx}] = {expr1} *E689* | 3064 :let {var-name}[{idx}] = {expr1} *E689* *E1141* |
3058 Set a list item to the result of the expression | 3065 Set a list item to the result of the expression |
3059 {expr1}. {var-name} must refer to a list and {idx} | 3066 {expr1}. {var-name} must refer to a list and {idx} |
3060 must be a valid index in that list. For nested list | 3067 must be a valid index in that list. For nested list |
3061 the index can be repeated. | 3068 the index can be repeated. |
3062 This cannot be used to add an item to a |List|. | 3069 This cannot be used to add an item to a |List|. |
3159 :let &g:{option-name} .= {expr1} | 3166 :let &g:{option-name} .= {expr1} |
3160 :let &g:{option-name} += {expr1} | 3167 :let &g:{option-name} += {expr1} |
3161 :let &g:{option-name} -= {expr1} | 3168 :let &g:{option-name} -= {expr1} |
3162 Like above, but only set the global value of an option | 3169 Like above, but only set the global value of an option |
3163 (if there is one). Works like |:setglobal|. | 3170 (if there is one). Works like |:setglobal|. |
3164 | 3171 *E1093* |
3165 :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* | 3172 :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* |
3166 {expr1} must evaluate to a |List|. The first item in | 3173 {expr1} must evaluate to a |List|. The first item in |
3167 the list is assigned to {name1}, the second item to | 3174 the list is assigned to {name1}, the second item to |
3168 {name2}, etc. | 3175 {name2}, etc. |
3169 The number of names must match the number of items in | 3176 The number of names must match the number of items in |
3200 :let [{name}, ..., ; {lastname}] -= {expr1} | 3207 :let [{name}, ..., ; {lastname}] -= {expr1} |
3201 Like above, but append/add/subtract the value for each | 3208 Like above, but append/add/subtract the value for each |
3202 |List| item. | 3209 |List| item. |
3203 | 3210 |
3204 *:let=<<* *:let-heredoc* | 3211 *:let=<<* *:let-heredoc* |
3205 *E990* *E991* *E172* *E221* | 3212 *E990* *E991* *E172* *E221* *E1145* |
3206 :let {var-name} =<< [trim] {endmarker} | 3213 :let {var-name} =<< [trim] {endmarker} |
3207 text... | 3214 text... |
3208 text... | 3215 text... |
3209 {endmarker} | 3216 {endmarker} |
3210 Set internal variable {var-name} to a |List| | 3217 Set internal variable {var-name} to a |List| |
3353 it can no longer be changed (until it is unlocked). | 3360 it can no longer be changed (until it is unlocked). |
3354 A locked variable can be deleted: > | 3361 A locked variable can be deleted: > |
3355 :lockvar v | 3362 :lockvar v |
3356 :let v = 'asdf' " fails! | 3363 :let v = 'asdf' " fails! |
3357 :unlet v " works | 3364 :unlet v " works |
3358 < *E741* *E940* | 3365 < *E741* *E940* *E1118* *E1119* *E1120* *E1121* *E1122* |
3359 If you try to change a locked variable you get an | 3366 If you try to change a locked variable you get an |
3360 error message: "E741: Value is locked: {name}". | 3367 error message: "E741: Value is locked: {name}". |
3361 If you try to lock or unlock a built-in variable you | 3368 If you try to lock or unlock a built-in variable you |
3362 get an error message: "E940: Cannot lock or unlock | 3369 get an error message: "E940: Cannot lock or unlock |
3363 variable {name}". | 3370 variable {name}". |
3496 When {object} is a |Blob|, Vim always makes a copy to | 3503 When {object} is a |Blob|, Vim always makes a copy to |
3497 iterate over. Unlike with |List|, modifying the | 3504 iterate over. Unlike with |List|, modifying the |
3498 |Blob| does not affect the iteration. | 3505 |Blob| does not affect the iteration. |
3499 | 3506 |
3500 :for [{var1}, {var2}, ...] in {listlist} | 3507 :for [{var1}, {var2}, ...] in {listlist} |
3501 :endfo[r] | 3508 :endfo[r] *E1140* |
3502 Like ":for" above, but each item in {listlist} must be | 3509 Like ":for" above, but each item in {listlist} must be |
3503 a list, of which each item is assigned to {var1}, | 3510 a list, of which each item is assigned to {var1}, |
3504 {var2}, etc. Example: > | 3511 {var2}, etc. Example: > |
3505 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]] | 3512 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]] |
3506 :echo getline(lnum)[col] | 3513 :echo getline(lnum)[col] |
3599 |:try| and the ":finally" is left: either by falling | 3606 |:try| and the ":finally" is left: either by falling |
3600 through to the ":finally" or by a |:continue|, | 3607 through to the ":finally" or by a |:continue|, |
3601 |:break|, |:finish|, or |:return|, or by an error or | 3608 |:break|, |:finish|, or |:return|, or by an error or |
3602 interrupt or exception (see |:throw|). | 3609 interrupt or exception (see |:throw|). |
3603 | 3610 |
3604 *:th* *:throw* *E608* | 3611 *:th* *:throw* *E608* *E1129* |
3605 :th[row] {expr1} The {expr1} is evaluated and thrown as an exception. | 3612 :th[row] {expr1} The {expr1} is evaluated and thrown as an exception. |
3606 If the ":throw" is used after a |:try| but before the | 3613 If the ":throw" is used after a |:try| but before the |
3607 first corresponding |:catch|, commands are skipped | 3614 first corresponding |:catch|, commands are skipped |
3608 until the first ":catch" matching {expr1} is reached. | 3615 until the first ":catch" matching {expr1} is reached. |
3609 If there is no such ":catch" or if the ":throw" is | 3616 If there is no such ":catch" or if the ":throw" is |