comparison runtime/doc/eval.txt @ 27321:3649b5a6b1b6

Update runtime files Commit: https://github.com/vim/vim/commit/6f4754b9f7253d7e4ba527064a24aff1acdb1e8f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 23 12:07:04 2022 +0000 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Jan 2022 13:15:05 +0100
parents 3e661b0cf500
children 5825405e4e2c
comparison
equal deleted inserted replaced
27320:6c9018237bfa 27321:3649b5a6b1b6
1 *eval.txt* For Vim version 8.2. Last change: 2022 Jan 08 1 *eval.txt* For Vim version 8.2. Last change: 2022 Jan 21
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
7 Expression evaluation *expression* *expr* *E15* *eval* 7 Expression evaluation *expression* *expr* *E15* *eval*
8 8 *E1002*
9 Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|. 9 Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|.
10 10
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|.
51 Number A 32 or 64 bit signed number. |expr-number| 51 Number A 32 or 64 bit signed number. |expr-number|
52 The number of bits is available in |v:numbersize|. 52 The number of bits is available in |v:numbersize|.
53 Examples: -123 0x10 0177 0o177 0b1011 53 Examples: -123 0x10 0177 0o177 0b1011
54 54
55 Float A floating point number. |floating-point-format| *Float* 55 Float A floating point number. |floating-point-format| *Float*
56 {only when compiled with the |+float| feature} 56 {only when compiled with the |+float| feature} *E1076*
57 Examples: 123.456 1.15e-6 -1.1e3 57 Examples: 123.456 1.15e-6 -1.1e3
58 58
59 String A NUL terminated string of 8-bit unsigned characters (bytes). 59 String A NUL terminated string of 8-bit unsigned characters (bytes).
60 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c' 60 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
61 61
1028 *expr-==#* *expr-!=#* *expr->#* *expr->=#* 1028 *expr-==#* *expr-!=#* *expr->#* *expr->=#*
1029 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#* 1029 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#*
1030 *expr-==?* *expr-!=?* *expr->?* *expr->=?* 1030 *expr-==?* *expr-!=?* *expr->?* *expr->=?*
1031 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?* 1031 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?*
1032 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#* 1032 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#*
1033 *expr-is?* *expr-isnot?* 1033 *expr-is?* *expr-isnot?* *E1072*
1034 use 'ignorecase' match case ignore case ~ 1034 use 'ignorecase' match case ignore case ~
1035 equal == ==# ==? 1035 equal == ==# ==?
1036 not equal != !=# !=? 1036 not equal != !=# !=?
1037 greater than > ># >? 1037 greater than > ># >?
1038 greater than or equal >= >=# >=? 1038 greater than or equal >= >=# >=?
1069 1069
1070 To compare Funcrefs to see if they refer to the same function, ignoring bound 1070 To compare Funcrefs to see if they refer to the same function, ignoring bound
1071 Dictionary and arguments, use |get()| to get the function name: > 1071 Dictionary and arguments, use |get()| to get the function name: >
1072 if get(Part1, 'name') == get(Part2, 'name') 1072 if get(Part1, 'name') == get(Part2, 'name')
1073 " Part1 and Part2 refer to the same function 1073 " Part1 and Part2 refer to the same function
1074 1074 < *E1037*
1075 Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether 1075 Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether
1076 the expressions are referring to the same |List|, |Dictionary| or |Blob| 1076 the expressions are referring to the same |List|, |Dictionary| or |Blob|
1077 instance. A copy of a |List| is different from the original |List|. When 1077 instance. A copy of a |List| is different from the original |List|. When
1078 using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to 1078 using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to
1079 using "equal", using "isnot" equivalent to using "not equal". Except that 1079 using "equal", using "isnot" equivalent to using "not equal". Except that
1121 can be matched like an ordinary character. Examples: 1121 can be matched like an ordinary character. Examples:
1122 "foo\nbar" =~ "\n" evaluates to 1 1122 "foo\nbar" =~ "\n" evaluates to 1
1123 "foo\nbar" =~ "\\n" evaluates to 0 1123 "foo\nbar" =~ "\\n" evaluates to 0
1124 1124
1125 1125
1126 expr5 and expr6 *expr5* *expr6* 1126 expr5 and expr6 *expr5* *expr6* *E1036* *E1051*
1127 --------------- 1127 ---------------
1128 expr6 + expr6 Number addition, |List| or |Blob| concatenation *expr-+* 1128 expr6 + expr6 Number addition, |List| or |Blob| concatenation *expr-+*
1129 expr6 - expr6 Number subtraction *expr--* 1129 expr6 - expr6 Number subtraction *expr--*
1130 expr6 . expr6 String concatenation *expr-.* 1130 expr6 . expr6 String concatenation *expr-.*
1131 expr6 .. expr6 String concatenation *expr-..* 1131 expr6 .. expr6 String concatenation *expr-..*
1180 1180
1181 When the righthand side of '%' is zero, the result is 0. 1181 When the righthand side of '%' is zero, the result is 0.
1182 1182
1183 None of these work for |Funcref|s. 1183 None of these work for |Funcref|s.
1184 1184
1185 ".", ".." and "%" do not work for Float. *E804* 1185 ".", ".." and "%" do not work for Float. *E804* *E1035*
1186 1186
1187 1187
1188 expr7 *expr7* 1188 expr7 *expr7*
1189 ----- 1189 -----
1190 <type>expr8 1190 <type>expr8
1227 expr9(expr1, ...)[expr1].name 1227 expr9(expr1, ...)[expr1].name
1228 expr9->(expr1, ...)[expr1] 1228 expr9->(expr1, ...)[expr1]
1229 Evaluation is always from left to right. 1229 Evaluation is always from left to right.
1230 1230
1231 expr9[expr1] item of String or |List| *expr-[]* *E111* 1231 expr9[expr1] item of String or |List| *expr-[]* *E111*
1232 *E909* *subscript* 1232 *E909* *subscript* *E1062*
1233 In legacy Vim script: 1233 In legacy Vim script:
1234 If expr9 is a Number or String this results in a String that contains the 1234 If expr9 is a Number or String this results in a String that contains the
1235 expr1'th single byte from expr9. expr9 is used as a String (a number is 1235 expr1'th single byte from expr9. expr9 is used as a String (a number is
1236 automatically converted to a String), expr1 as a Number. This doesn't 1236 automatically converted to a String), expr1 as a Number. This doesn't
1237 recognize multibyte encodings, see `byteidx()` for an alternative, or use 1237 recognize multibyte encodings, see `byteidx()` for an alternative, or use
1362 -1.234->string() 1362 -1.234->string()
1363 Is equivalent to: > 1363 Is equivalent to: >
1364 (-1.234)->string() 1364 (-1.234)->string()
1365 And NOT: > 1365 And NOT: >
1366 -(1.234->string()) 1366 -(1.234->string())
1367 < 1367
1368 What comes after "->" can be a name, a simple expression (not containing any
1369 parenthesis), or any expression in parenthesis: >
1370 base->name(args)
1371 base->some.name(args)
1372 base->alist[idx](args)
1373 base->(getFuncRef())(args)
1374 Note that in the last call the base is passed to the function resulting from
1375 "(getFuncRef())", inserted before "args".
1376
1368 *E274* 1377 *E274*
1369 "->name(" must not contain white space. There can be white space before the 1378 "->name(" must not contain white space. There can be white space before the
1370 "->" and after the "(", thus you can split the lines like this: > 1379 "->" and after the "(", thus you can split the lines like this: >
1371 mylist 1380 mylist
1372 \ ->filter(filterexpr) 1381 \ ->filter(filterexpr)
1566 :echo expand("$shell") 1575 :echo expand("$shell")
1567 The first one probably doesn't echo anything, the second echoes the $shell 1576 The first one probably doesn't echo anything, the second echoes the $shell
1568 variable (if your shell supports it). 1577 variable (if your shell supports it).
1569 1578
1570 1579
1571 internal variable *expr-variable* 1580 internal variable *expr-variable* *E1015*
1572 ----------------- 1581 -----------------
1573 variable internal variable 1582 variable internal variable
1574 See below |internal-variables|. 1583 See below |internal-variables|.
1575 1584
1576 1585
1654 for a lambda expression, you can find what it is with the following command: > 1663 for a lambda expression, you can find what it is with the following command: >
1655 :function <lambda>42 1664 :function <lambda>42
1656 See also: |numbered-function| 1665 See also: |numbered-function|
1657 1666
1658 ============================================================================== 1667 ==============================================================================
1659 3. Internal variable *internal-variables* *E461* 1668 3. Internal variable *internal-variables* *E461* *E1001*
1660 1669
1661 An internal variable name can be made up of letters, digits and '_'. But it 1670 An internal variable name can be made up of letters, digits and '_'. But it
1662 cannot start with a digit. In legacy script it is also possible to use curly 1671 cannot start with a digit. In legacy script it is also possible to use curly
1663 braces, see |curly-braces-names|. 1672 braces, see |curly-braces-names|.
1664 1673
1812 Note that this means that filetype plugins don't get a different set of script 1821 Note that this means that filetype plugins don't get a different set of script
1813 variables for each buffer. Use local buffer variables instead |b:var|. 1822 variables for each buffer. Use local buffer variables instead |b:var|.
1814 1823
1815 1824
1816 PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:* 1825 PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:*
1817 *E963* 1826 *E963* *E1063*
1818 Some variables can be set by the user, but the type cannot be changed. 1827 Some variables can be set by the user, but the type cannot be changed.
1819 1828
1820 *v:argv* *argv-variable* 1829 *v:argv* *argv-variable*
1821 v:argv The command line arguments Vim was invoked with. This is a 1830 v:argv The command line arguments Vim was invoked with. This is a
1822 list of strings. The first item is the Vim command. 1831 list of strings. The first item is the Vim command.
2828 :let [success, div] = Compute(102, 6) 2837 :let [success, div] = Compute(102, 6)
2829 :if success == "ok" 2838 :if success == "ok"
2830 : echo div 2839 : echo div
2831 :endif 2840 :endif
2832 < 2841 <
2833 *:cal* *:call* *E107* *E117* 2842 *:cal* *:call* *E107*
2834 :[range]cal[l] {name}([arguments]) 2843 :[range]cal[l] {name}([arguments])
2835 Call a function. The name of the function and its arguments 2844 Call a function. The name of the function and its arguments
2836 are as specified with `:function`. Up to 20 arguments can be 2845 are as specified with `:function`. Up to 20 arguments can be
2837 used. The returned value is discarded. 2846 used. The returned value is discarded.
2838 In |Vim9| script using `:call` is optional, these two lines do 2847 In |Vim9| script using `:call` is optional, these two lines do
2872 When the function returns a composite value it can be further 2881 When the function returns a composite value it can be further
2873 dereferenced, but the range will not be used then. Example: > 2882 dereferenced, but the range will not be used then. Example: >
2874 :4,8call GetDict().method() 2883 :4,8call GetDict().method()
2875 < Here GetDict() gets the range but method() does not. 2884 < Here GetDict() gets the range but method() does not.
2876 2885
2886 *E117*
2887 When a function cannot be found the error "E117: Unknown function" will be
2888 given. If the function was using an autoload path or an autoload import and
2889 the script is a |Vim9| script, this may also be caused by the function not
2890 being exported.
2891
2877 *E132* 2892 *E132*
2878 The recursiveness of user functions is restricted with the |'maxfuncdepth'| 2893 The recursiveness of user functions is restricted with the |'maxfuncdepth'|
2879 option. 2894 option.
2880 2895
2881 It is also possible to use `:eval`. It does not support a range, but does 2896 It is also possible to use `:eval`. It does not support a range, but does
2970 Vim or manually source the script. 2985 Vim or manually source the script.
2971 2986
2972 Also note that if you have two script files, and one calls a function in the 2987 Also note that if you have two script files, and one calls a function in the
2973 other and vice versa, before the used function is defined, it won't work. 2988 other and vice versa, before the used function is defined, it won't work.
2974 Avoid using the autoload functionality at the toplevel. 2989 Avoid using the autoload functionality at the toplevel.
2990
2991 In |Vim9| script you will get error *E1263* if you use a function name with a
2992 "#" character when not in an autoload script.
2975 2993
2976 Hint: If you distribute a bunch of scripts you can pack them together with the 2994 Hint: If you distribute a bunch of scripts you can pack them together with the
2977 |vimball| utility. Also read the user manual |distribute-script|. 2995 |vimball| utility. Also read the user manual |distribute-script|.
2978 2996
2979 ============================================================================== 2997 ==============================================================================
3057 {idx1} can be omitted, zero is used instead. 3075 {idx1} can be omitted, zero is used instead.
3058 {idx2} can be omitted, meaning the end of the list. 3076 {idx2} can be omitted, meaning the end of the list.
3059 When the selected range of items is partly past the 3077 When the selected range of items is partly past the
3060 end of the list, items will be added. 3078 end of the list, items will be added.
3061 3079
3062 *:let+=* *:let-=* *:letstar=* 3080 *:let+=* *:let-=* *:letstar=* *:let/=* *:let%=*
3063 *:let/=* *:let%=* *:let.=* *:let..=* *E734* *E985* 3081 *:let.=* *:let..=* *E734* *E985* *E1019*
3064 :let {var} += {expr1} Like ":let {var} = {var} + {expr1}". 3082 :let {var} += {expr1} Like ":let {var} = {var} + {expr1}".
3065 :let {var} -= {expr1} Like ":let {var} = {var} - {expr1}". 3083 :let {var} -= {expr1} Like ":let {var} = {var} - {expr1}".
3066 :let {var} *= {expr1} Like ":let {var} = {var} * {expr1}". 3084 :let {var} *= {expr1} Like ":let {var} = {var} * {expr1}".
3067 :let {var} /= {expr1} Like ":let {var} = {var} / {expr1}". 3085 :let {var} /= {expr1} Like ":let {var} = {var} / {expr1}".
3068 :let {var} %= {expr1} Like ":let {var} = {var} % {expr1}". 3086 :let {var} %= {expr1} Like ":let {var} = {var} % {expr1}".
3261 <nothing> String 3279 <nothing> String
3262 # Number 3280 # Number
3263 * Funcref 3281 * Funcref
3264 This does not work in Vim9 script. |vim9-declaration| 3282 This does not work in Vim9 script. |vim9-declaration|
3265 3283
3266 :unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* 3284 :unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* *E1081*
3267 Remove the internal variable {name}. Several variable 3285 Remove the internal variable {name}. Several variable
3268 names can be given, they are all removed. The name 3286 names can be given, they are all removed. The name
3269 may also be a |List| or |Dictionary| item. 3287 may also be a |List| or |Dictionary| item.
3270 With [!] no error message is given for non-existing 3288 With [!] no error message is given for non-existing
3271 variables. 3289 variables.
3287 No error message is given for a non-existing 3305 No error message is given for a non-existing
3288 variable, also without !. 3306 variable, also without !.
3289 If the system does not support deleting an environment 3307 If the system does not support deleting an environment
3290 variable, it is made empty. 3308 variable, it is made empty.
3291 3309
3292 *:cons* *:const* 3310 *:cons* *:const* *E1018*
3293 :cons[t] {var-name} = {expr1} 3311 :cons[t] {var-name} = {expr1}
3294 :cons[t] [{name1}, {name2}, ...] = {expr1} 3312 :cons[t] [{name1}, {name2}, ...] = {expr1}
3295 :cons[t] [{name}, ..., ; {lastname}] = {expr1} 3313 :cons[t] [{name}, ..., ; {lastname}] = {expr1}
3296 :cons[t] {var-name} =<< [trim] {marker} 3314 :cons[t] {var-name} =<< [trim] {marker}
3297 text... 3315 text...
3507 commands following the ":finally" up to the matching 3525 commands following the ":finally" up to the matching
3508 |:endtry| are executed first. This process applies to 3526 |:endtry| are executed first. This process applies to
3509 all nested ":try"s inside the loop. The outermost 3527 all nested ":try"s inside the loop. The outermost
3510 ":endtry" then jumps to the command after the loop. 3528 ":endtry" then jumps to the command after the loop.
3511 3529
3512 :try *:try* *:endt* *:endtry* *E600* *E601* *E602* 3530 :try *:try* *:endt* *:endtry*
3531 *E600* *E601* *E602* *E1032*
3513 :endt[ry] Change the error handling for the commands between 3532 :endt[ry] Change the error handling for the commands between
3514 ":try" and ":endtry" including everything being 3533 ":try" and ":endtry" including everything being
3515 executed across ":source" commands, function calls, 3534 executed across ":source" commands, function calls,
3516 or autocommand invocations. 3535 or autocommand invocations.
3517 3536
3543 the error number. 3562 the error number.
3544 Examples: > 3563 Examples: >
3545 try | sleep 100 | catch /^Vim:Interrupt$/ | endtry 3564 try | sleep 100 | catch /^Vim:Interrupt$/ | endtry
3546 try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry 3565 try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry
3547 < 3566 <
3548 *:cat* *:catch* *E603* *E604* *E605* 3567 *:cat* *:catch*
3568 *E603* *E604* *E605* *E654* *E1033*
3549 :cat[ch] /{pattern}/ The following commands until the next |:catch|, 3569 :cat[ch] /{pattern}/ The following commands until the next |:catch|,
3550 |:finally|, or |:endtry| that belongs to the same 3570 |:finally|, or |:endtry| that belongs to the same
3551 |:try| as the ":catch" are executed when an exception 3571 |:try| as the ":catch" are executed when an exception
3552 matching {pattern} is being thrown and has not yet 3572 matching {pattern} is being thrown and has not yet
3553 been caught by a previous ":catch". Otherwise, these 3573 been caught by a previous ":catch". Otherwise, these
3564 :catch " same as /.*/ 3584 :catch " same as /.*/
3565 < 3585 <
3566 Another character can be used instead of / around the 3586 Another character can be used instead of / around the
3567 {pattern}, so long as it does not have a special 3587 {pattern}, so long as it does not have a special
3568 meaning (e.g., '|' or '"') and doesn't occur inside 3588 meaning (e.g., '|' or '"') and doesn't occur inside
3569 {pattern}. 3589 {pattern}. *E1067*
3570 Information about the exception is available in 3590 Information about the exception is available in
3571 |v:exception|. Also see |throw-variables|. 3591 |v:exception|. Also see |throw-variables|.
3572 NOTE: It is not reliable to ":catch" the TEXT of 3592 NOTE: It is not reliable to ":catch" the TEXT of
3573 an error message because it may vary in different 3593 an error message because it may vary in different
3574 locales. 3594 locales.