comparison runtime/doc/eval.txt @ 27036:3e661b0cf500

Update runtime files Commit: https://github.com/vim/vim/commit/2f0936cb9a2eb026acac03e6a8fd0b2a5d97508b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 8 21:51:59 2022 +0000 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sat, 08 Jan 2022 23:00:06 +0100
parents fb67cd7d30a7
children 3649b5a6b1b6
comparison
equal deleted inserted replaced
27035:5232c68bb21d 27036:3e661b0cf500
1 *eval.txt* For Vim version 8.2. Last change: 2021 Dec 28 1 *eval.txt* For Vim version 8.2. Last change: 2022 Jan 08
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
11 Note: Expression evaluation can be disabled at compile time. If this has been 11 Note: Expression evaluation can be disabled at compile time. If this has been
12 done, the features in this document are not available. See |+eval| and 12 done, the features in this document are not available. See |+eval| and
13 |no-eval-feature|. 13 |no-eval-feature|.
14 14
15 This file is mainly about the backwards compatible (legacy) Vim script. For 15 This file is mainly about the backwards compatible (legacy) Vim script. For
16 specifics of Vim9 script, which executes much faster, supports type checking 16 specifics of Vim9 script, which can execute much faster, supports type
17 and much more, see |vim9.txt|. Where the syntax or semantics differ a remark 17 checking and much more, see |vim9.txt|. Where the syntax or semantics differ
18 is given. 18 a remark is given.
19 19
20 1. Variables |variables| 20 1. Variables |variables|
21 1.1 Variable types 21 1.1 Variable types
22 1.2 Function references |Funcref| 22 1.2 Function references |Funcref|
23 1.3 Lists |Lists| 23 1.3 Lists |Lists|
160 argument is present and it evaluates to a non-zero Number, |v:true| or a 160 argument is present and it evaluates to a non-zero Number, |v:true| or a
161 non-empty String, then the value is considered to be TRUE. 161 non-empty String, then the value is considered to be TRUE.
162 Note that " " and "0" are also non-empty strings, thus considered to be TRUE. 162 Note that " " and "0" are also non-empty strings, thus considered to be TRUE.
163 A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE. 163 A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE.
164 164
165 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* 165 *E611* *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910*
166 *E974* *E975* *E976* 166 *E913* *E974* *E975* *E976*
167 |List|, |Dictionary|, |Funcref|, |Job|, |Channel| and |Blob| types are not 167 |List|, |Dictionary|, |Funcref|, |Job|, |Channel| and |Blob| types are not
168 automatically converted. 168 automatically converted.
169 169
170 *E805* *E806* *E808* 170 *E805* *E806* *E808*
171 When mixing Number and Float the Number is converted to Float. Otherwise 171 When mixing Number and Float the Number is converted to Float. Otherwise
172 there is no automatic conversion of Float. You can use str2float() for String 172 there is no automatic conversion of Float. You can use str2float() for String
173 to Float, printf() for Float to String and float2nr() for Float to Number. 173 to Float, printf() for Float to String and float2nr() for Float to Number.
174 174
175 *E891* *E892* *E893* *E894* *E907* *E911* *E914* 175 *E362* *E891* *E892* *E893* *E894* *E907* *E911* *E914*
176 When expecting a Float a Number can also be used, but nothing else. 176 When expecting a Float a Number can also be used, but nothing else.
177 177
178 *no-type-checking* 178 *no-type-checking*
179 You will not get an error if you try to change the type of a variable. 179 You will not get an error if you try to change the type of a variable.
180 180
1344 When expr9 is a |Funcref| type variable, invoke the function it refers to. 1344 When expr9 is a |Funcref| type variable, invoke the function it refers to.
1345 1345
1346 1346
1347 expr9->name([args]) method call *method* *->* 1347 expr9->name([args]) method call *method* *->*
1348 expr9->{lambda}([args]) 1348 expr9->{lambda}([args])
1349 *E276* 1349 *E260* *E276*
1350 For methods that are also available as global functions this is the same as: > 1350 For methods that are also available as global functions this is the same as: >
1351 name(expr9 [, args]) 1351 name(expr9 [, args])
1352 There can also be methods specifically for the type of "expr9". 1352 There can also be methods specifically for the type of "expr9".
1353 1353
1354 This allows for chaining, passing the value that one method returns to the 1354 This allows for chaining, passing the value that one method returns to the
1580 See below |functions|. 1580 See below |functions|.
1581 1581
1582 1582
1583 lambda expression *expr-lambda* *lambda* 1583 lambda expression *expr-lambda* *lambda*
1584 ----------------- 1584 -----------------
1585 {args -> expr1} legacy lambda expression 1585 {args -> expr1} legacy lambda expression *E451*
1586 (args) => expr1 |Vim9| lambda expression 1586 (args) => expr1 |Vim9| lambda expression
1587 1587
1588 A lambda expression creates a new unnamed function which returns the result of 1588 A lambda expression creates a new unnamed function which returns the result of
1589 evaluating |expr1|. Lambda expressions differ from |user-functions| in 1589 evaluating |expr1|. Lambda expressions differ from |user-functions| in
1590 the following ways: 1590 the following ways:
1657 1657
1658 ============================================================================== 1658 ==============================================================================
1659 3. Internal variable *internal-variables* *E461* 1659 3. Internal variable *internal-variables* *E461*
1660 1660
1661 An internal variable name can be made up of letters, digits and '_'. But it 1661 An internal variable name can be made up of letters, digits and '_'. But it
1662 cannot start with a digit. In legacy script it also possible to use curly 1662 cannot start with a digit. In legacy script it is also possible to use curly
1663 braces, see |curly-braces-names|. 1663 braces, see |curly-braces-names|.
1664 1664
1665 In legacy script ann internal variable is created with the ":let" command 1665 In legacy script an internal variable is created with the ":let" command
1666 |:let|. An internal variable is explicitly destroyed with the ":unlet" 1666 |:let|. An internal variable is explicitly destroyed with the ":unlet"
1667 command |:unlet|. 1667 command |:unlet|.
1668 Using a name that is not an internal variable or refers to a variable that has 1668 Using a name that is not an internal variable or refers to a variable that has
1669 been destroyed results in an error. 1669 been destroyed results in an error.
1670 1670
2160 and 'guitabtooltip'. Only valid while one of these 2160 and 'guitabtooltip'. Only valid while one of these
2161 expressions is being evaluated. Read-only when in the 2161 expressions is being evaluated. Read-only when in the
2162 |sandbox|. 2162 |sandbox|.
2163 2163
2164 *v:maxcol* *maxcol-variable* 2164 *v:maxcol* *maxcol-variable*
2165 v:maxcol Maximum line length. 2165 v:maxcol Maximum line length. Depending on where it is used it can be
2166 screen columns, characters or bytes.
2166 2167
2167 *v:mouse_win* *mouse_win-variable* 2168 *v:mouse_win* *mouse_win-variable*
2168 v:mouse_win Window number for a mouse click obtained with |getchar()|. 2169 v:mouse_win Window number for a mouse click obtained with |getchar()|.
2169 First window has number 1, like with |winnr()|. The value is 2170 First window has number 1, like with |winnr()|. The value is
2170 zero when there was no mouse button click. 2171 zero when there was no mouse button click.
2571 functions. 2572 functions.
2572 2573
2573 In |Vim9| script functions are local to the script by default, prefix "g:" to 2574 In |Vim9| script functions are local to the script by default, prefix "g:" to
2574 define a global function. 2575 define a global function.
2575 2576
2576 *:fu* *:function* *E128* *E129* *E123* 2577 *:fu* *:function* *E128* *E129* *E123* *E454*
2577 :fu[nction] List all functions and their arguments. 2578 :fu[nction] List all functions and their arguments.
2578 2579
2579 :fu[nction] {name} List function {name}. 2580 :fu[nction] {name} List function {name}.
2580 {name} can also be a |Dictionary| entry that is a 2581 {name} can also be a |Dictionary| entry that is a
2581 |Funcref|: > 2582 |Funcref|: >
2697 2698
2698 To be able to define a function inside an `:execute` 2699 To be able to define a function inside an `:execute`
2699 command, use line breaks instead of |:bar|: > 2700 command, use line breaks instead of |:bar|: >
2700 :exe "func Foo()\necho 'foo'\nendfunc" 2701 :exe "func Foo()\necho 'foo'\nendfunc"
2701 < 2702 <
2702 *:delf* *:delfunction* *E130* *E131* *E933* 2703 *:delf* *:delfunction* *E131* *E933*
2703 :delf[unction][!] {name} 2704 :delf[unction][!] {name}
2704 Delete function {name}. 2705 Delete function {name}.
2705 {name} can also be a |Dictionary| entry that is a 2706 {name} can also be a |Dictionary| entry that is a
2706 |Funcref|: > 2707 |Funcref|: >
2707 :delfunc dict.init 2708 :delfunc dict.init
4944 When the |+eval| feature is available the command is skipped because of the 4945 When the |+eval| feature is available the command is skipped because of the
4945 "while 0". Without the |+eval| feature the "while 0" is an error, which is 4946 "while 0". Without the |+eval| feature the "while 0" is an error, which is
4946 silently ignored, and the command is executed. 4947 silently ignored, and the command is executed.
4947 4948
4948 ============================================================================== 4949 ==============================================================================
4949 12. The sandbox *eval-sandbox* *sandbox* *E48* 4950 12. The sandbox *eval-sandbox* *sandbox*
4950 4951
4951 The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and 4952 The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and
4952 'foldtext' options may be evaluated in a sandbox. This means that you are 4953 'foldtext' options may be evaluated in a sandbox. This means that you are
4953 protected from these expressions having nasty side effects. This gives some 4954 protected from these expressions having nasty side effects. This gives some
4954 safety for when these options are set from a modeline. It is also used when 4955 safety for when these options are set from a modeline. It is also used when
4955 the command from a tags file is executed and for CTRL-R = in the command line. 4956 the command from a tags file is executed and for CTRL-R = in the command line.
4956 The sandbox is also used for the |:sandbox| command. 4957 The sandbox is also used for the |:sandbox| command.
4957 4958 *E48*
4958 These items are not allowed in the sandbox: 4959 These items are not allowed in the sandbox:
4959 - changing the buffer text 4960 - changing the buffer text
4960 - defining or changing mapping, autocommands, user commands 4961 - defining or changing mapping, autocommands, user commands
4961 - setting certain options (see |option-summary|) 4962 - setting certain options (see |option-summary|)
4962 - setting certain v: variables (see |v:var|) *E794* 4963 - setting certain v: variables (see |v:var|) *E794*