1
- *eval.txt* For Vim version 8.2. Last change: 2022 May 13
1
+ *eval.txt* For Vim version 8.2. Last change: 2022 Jun 03
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -183,10 +183,15 @@ You will not get an error if you try to change the type of a variable.
183
183
1.2 Function references ~
184
184
*Funcref* *E695* *E718* *E1192*
185
185
A Funcref variable is obtained with the | function() | function, the | funcref() |
186
- function or created with the lambda expression | expr-lambda | . It can be used
187
- in an expression in the place of a function name, before the parenthesis
188
- around the arguments, to invoke the function it refers to. Example: >
186
+ function, (in | Vim9 | script) the name of a function, or created with the
187
+ lambda expression | expr-lambda | . It can be used in an expression in the place
188
+ of a function name, before the parenthesis around the arguments, to invoke the
189
+ function it refers to. Example in | Vim9 | script: >
189
190
191
+ :var Fn = MyFunc
192
+ :echo Fn()
193
+
194
+ Legacy script: >
190
195
:let Fn = function("MyFunc")
191
196
:echo Fn()
192
197
< *E704* *E705* *E707*
@@ -526,7 +531,7 @@ entry. Note that the String '04' and the Number 04 are different, since the
526
531
Number will be converted to the String '4', leading zeros are dropped. The
527
532
empty string can also be used as a key.
528
533
529
- In | Vim9 | script literaly keys can be used if the key consists of alphanumeric
534
+ In | Vim9 | script literally keys can be used if the key consists of alphanumeric
530
535
characters, underscore and dash, see | vim9-literal-dict | .
531
536
*literal-Dict* *#{}*
532
537
To avoid having to put quotes around every key the #{} form can be used in
@@ -868,33 +873,36 @@ Expression syntax summary, from least to most significant:
868
873
expr5 isnot expr5 different | List | , | Dictionary | or | Blob |
869
874
instance
870
875
871
- | expr5 | expr6
872
- expr6 + expr6 ... number addition, list or blob concatenation
873
- expr6 - expr6 ... number subtraction
874
- expr6 . expr6 ... string concatenation
875
- expr6 .. expr6 ... string concatenation
876
+ | expr5 | expr6 << expr6 bitwise left shift
877
+ expr6 >> expr6 bitwise right shift
876
878
877
879
| expr6 | expr7
878
- expr7 * expr7 ... number multiplication
879
- expr7 / expr7 ... number division
880
- expr7 % expr7 ... number modulo
880
+ expr7 + expr7 ... number addition, list or blob concatenation
881
+ expr7 - expr7 ... number subtraction
882
+ expr7 . expr7 ... string concatenation
883
+ expr7 .. expr7 ... string concatenation
881
884
882
885
| expr7 | expr8
883
- <type> expr8 type check and conversion (| Vim9 | only)
886
+ expr8 * expr8 ... number multiplication
887
+ expr8 / expr8 ... number division
888
+ expr8 % expr8 ... number modulo
884
889
885
890
| expr8 | expr9
886
- ! expr8 logical NOT
887
- - expr8 unary minus
888
- + expr8 unary plus
891
+ <type> expr9 type check and conversion (| Vim9 | only)
889
892
890
893
| expr9 | expr10
891
- expr9[expr1] byte of a String or item of a | List |
892
- expr9[expr1 : expr1] substring of a String or sublist of a | List |
893
- expr9.name entry in a | Dictionary |
894
- expr9(expr1, ...) function call with | Funcref | variable
895
- expr9->name(expr1, ...) | method | call
896
-
897
- | expr10 | number number constant
894
+ ! expr9 logical NOT
895
+ - expr9 unary minus
896
+ + expr9 unary plus
897
+
898
+ | expr10 | expr11
899
+ expr10[expr1] byte of a String or item of a | List |
900
+ expr10[expr1 : expr1] substring of a String or sublist of a | List |
901
+ expr10.name entry in a | Dictionary |
902
+ expr10(expr1, ...) function call with | Funcref | variable
903
+ expr10->name(expr1, ...) | method | call
904
+
905
+ | expr11 | number number constant
898
906
"string" string constant, backslash is special
899
907
'string' string constant, ' is doubled
900
908
[expr1, ...] | List |
@@ -1128,14 +1136,27 @@ can be matched like an ordinary character. Examples:
1128
1136
"foo\nbar" =~ "\\n" evaluates to 0
1129
1137
1130
1138
1131
- expr5 and expr6 *expr5* *expr6* *E1036* *E1051*
1139
+ expr5 *expr5* *bitwise-shift*
1140
+ -----
1141
+ expr6 << expr6 bitwise left shift *expr-<<*
1142
+ expr6 >> expr6 bitwise right shift *expr->>*
1143
+ *E1282* *E1283*
1144
+ The "<<" and ">>" operators can be used to perform bitwise left or right shift
1145
+ of the left operand by the number of bits specified by the right operand. The
1146
+ operands are used as positive numbers. When shifting right with ">>" the
1147
+ topmost bit (sometimes called the sign bit) is cleared. If the right operand
1148
+ (shift amount) is more than the maximum number of bits in a number
1149
+ (| v:numbersize | ) the result is zero.
1150
+
1151
+
1152
+ expr6 and expr7 *expr6* *expr7* *E1036* *E1051*
1132
1153
---------------
1133
- expr6 + expr6 Number addition, | List | or | Blob | concatenation *expr-+*
1134
- expr6 - expr6 Number subtraction *expr--*
1135
- expr6 . expr6 String concatenation *expr-.*
1136
- expr6 .. expr6 String concatenation *expr-..*
1154
+ expr7 + expr7 Number addition, | List | or | Blob | concatenation *expr-+*
1155
+ expr7 - expr7 Number subtraction *expr--*
1156
+ expr7 . expr7 String concatenation *expr-.*
1157
+ expr7 .. expr7 String concatenation *expr-..*
1137
1158
1138
- For | Lists | only "+" is possible and then both expr6 must be a list. The
1159
+ For | Lists | only "+" is possible and then both expr7 must be a list. The
1139
1160
result is a new list with the two lists Concatenated.
1140
1161
1141
1162
For String concatenation ".." is preferred, since "." is ambiguous, it is also
@@ -1147,9 +1168,9 @@ In |Vim9| script the arguments of ".." are converted to String for simple
1147
1168
types: Number, Float, Special and Bool. For other types | string() | should be
1148
1169
used.
1149
1170
1150
- expr7 * expr7 Number multiplication *expr-star*
1151
- expr7 / expr7 Number division *expr-/*
1152
- expr7 % expr7 Number modulo *expr-%*
1171
+ expr8 * expr8 Number multiplication *expr-star*
1172
+ expr8 / expr8 Number division *expr-/*
1173
+ expr8 % expr8 Number modulo *expr-%*
1153
1174
1154
1175
In legacy script, for all operators except "." and "..", Strings are converted
1155
1176
to Numbers.
@@ -1191,18 +1212,18 @@ None of these work for |Funcref|s.
1191
1212
".", ".." and "%" do not work for Float. *E804* *E1035*
1192
1213
1193
1214
1194
- expr7 *expr7 *
1215
+ expr8 *expr8 *
1195
1216
-----
1196
- <type> expr8
1217
+ <type> expr9
1197
1218
1198
1219
This is only available in | Vim9 | script, see | type-casting | .
1199
1220
1200
1221
1201
- expr8 *expr8 *
1222
+ expr9 *expr9 *
1202
1223
-----
1203
- ! expr8 logical NOT *expr-!*
1204
- - expr8 unary minus *expr-unary--*
1205
- + expr8 unary plus *expr-unary-+*
1224
+ ! expr9 logical NOT *expr-!*
1225
+ - expr9 unary minus *expr-unary--*
1226
+ + expr9 unary plus *expr-unary-+*
1206
1227
1207
1228
For '!' | TRUE | becomes | FALSE | , | FALSE | becomes | TRUE | (one).
1208
1229
For '-' the sign of the number is changed.
@@ -1224,30 +1245,30 @@ These three can be repeated and mixed. Examples:
1224
1245
--9 == 9
1225
1246
1226
1247
1227
- expr9 *expr9 *
1228
- -----
1229
- This expression is either | expr10 | or a sequence of the alternatives below,
1248
+ expr10 *expr10 *
1249
+ ------
1250
+ This expression is either | expr11 | or a sequence of the alternatives below,
1230
1251
in any order. E.g., these are all possible:
1231
- expr9 [expr1].name
1232
- expr9 .name[expr1]
1233
- expr9 (expr1, ...)[expr1].name
1234
- expr9 ->(expr1, ...)[expr1]
1252
+ expr10 [expr1].name
1253
+ expr10 .name[expr1]
1254
+ expr10 (expr1, ...)[expr1].name
1255
+ expr10 ->(expr1, ...)[expr1]
1235
1256
Evaluation is always from left to right.
1236
1257
1237
- expr9 [expr1] item of String or | List | *expr-[]* *E111*
1258
+ expr10 [expr1] item of String or | List | *expr-[]* *E111*
1238
1259
*E909* *subscript* *E1062*
1239
1260
In legacy Vim script:
1240
- If expr9 is a Number or String this results in a String that contains the
1241
- expr1'th single byte from expr9 . expr9 is used as a String (a number is
1261
+ If expr10 is a Number or String this results in a String that contains the
1262
+ expr1'th single byte from expr10 . expr10 is used as a String (a number is
1242
1263
automatically converted to a String), expr1 as a Number. This doesn't
1243
1264
recognize multibyte encodings, see `byteidx ()` for an alternative, or use
1244
1265
`split ()` to turn the string into a list of characters. Example, to get the
1245
1266
byte under the cursor: >
1246
1267
:let c = getline(".")[col(".") - 1]
1247
1268
1248
1269
In | Vim9 | script: *E1147* *E1148*
1249
- If expr9 is a String this results in a String that contains the expr1'th
1250
- single character (including any composing characters) from expr9 . To use byte
1270
+ If expr10 is a String this results in a String that contains the expr1'th
1271
+ single character (including any composing characters) from expr10 . To use byte
1251
1272
indexes use | strpart() | .
1252
1273
1253
1274
Index zero gives the first byte or character. Careful: text column numbers
@@ -1258,7 +1279,7 @@ String. A negative index always results in an empty string (reason: backward
1258
1279
compatibility). Use [-1:] to get the last byte or character.
1259
1280
In Vim9 script a negative index is used like with a list: count from the end.
1260
1281
1261
- If expr9 is a | List | then it results the item at index expr1. See | list-index |
1282
+ If expr10 is a | List | then it results the item at index expr1. See | list-index |
1262
1283
for possible index values. If the index is out of range this results in an
1263
1284
error. Example: >
1264
1285
:let item = mylist[-1] " get last item
@@ -1268,14 +1289,14 @@ Generally, if a |List| index is equal to or higher than the length of the
1268
1289
error.
1269
1290
1270
1291
1271
- expr9 [expr1a : expr1b] substring or sublist *expr-[:]*
1292
+ expr10 [expr1a : expr1b] substring or sublist *expr-[:]*
1272
1293
1273
- If expr9 is a String this results in the substring with the bytes or
1274
- characters from expr1a to and including expr1b. expr9 is used as a String,
1294
+ If expr10 is a String this results in the substring with the bytes or
1295
+ characters from expr1a to and including expr1b. expr10 is used as a String,
1275
1296
expr1a and expr1b are used as a Number.
1276
1297
1277
1298
In legacy Vim script the indexes are byte indexes. This doesn't recognize
1278
- multibyte encodings, see | byteidx() | for computing the indexes. If expr9 is
1299
+ multibyte encodings, see | byteidx() | for computing the indexes. If expr10 is
1279
1300
a Number it is first converted to a String.
1280
1301
1281
1302
In Vim9 script the indexes are character indexes and include composing
@@ -1302,20 +1323,20 @@ Examples: >
1302
1323
:let s = s[:-3] " remove last two bytes
1303
1324
<
1304
1325
*slice*
1305
- If expr9 is a | List | this results in a new | List | with the items indicated by
1326
+ If expr10 is a | List | this results in a new | List | with the items indicated by
1306
1327
the indexes expr1a and expr1b. This works like with a String, as explained
1307
1328
just above. Also see | sublist | below. Examples: >
1308
1329
:let l = mylist[:3] " first four items
1309
1330
:let l = mylist[4:4] " List with one item
1310
1331
:let l = mylist[:] " shallow copy of a List
1311
1332
1312
- If expr9 is a | Blob | this results in a new | Blob | with the bytes in the
1333
+ If expr10 is a | Blob | this results in a new | Blob | with the bytes in the
1313
1334
indexes expr1a and expr1b, inclusive. Examples: >
1314
1335
:let b = 0zDEADBEEF
1315
1336
:let bs = b[1:2] " 0zADBE
1316
1337
:let bs = b[:] " copy of 0zDEADBEEF
1317
1338
1318
- Using expr9 [expr1] or expr9 [expr1a : expr1b] on a | Funcref | results in an
1339
+ Using expr10 [expr1] or expr10 [expr1a : expr1b] on a | Funcref | results in an
1319
1340
error.
1320
1341
1321
1342
Watch out for confusion between a namespace and a variable followed by a colon
@@ -1324,11 +1345,11 @@ for a sublist: >
1324
1345
mylist[s:] " uses namespace s:, error!
1325
1346
1326
1347
1327
- expr9 .name entry in a | Dictionary | *expr-entry*
1348
+ expr10 .name entry in a | Dictionary | *expr-entry*
1328
1349
*E1203* *E1229*
1329
- If expr9 is a | Dictionary | and it is followed by a dot, then the following
1350
+ If expr10 is a | Dictionary | and it is followed by a dot, then the following
1330
1351
name will be used as a key in the | Dictionary | . This is just like:
1331
- expr9 [name].
1352
+ expr10 [name].
1332
1353
1333
1354
The name must consist of alphanumeric characters, just like a variable name,
1334
1355
but it may start with a number. Curly braces cannot be used.
@@ -1345,17 +1366,17 @@ Note that the dot is also used for String concatenation. To avoid confusion
1345
1366
always put spaces around the dot for String concatenation.
1346
1367
1347
1368
1348
- expr9 (expr1, ...) | Funcref | function call *E1085*
1369
+ expr10 (expr1, ...) | Funcref | function call *E1085*
1349
1370
1350
- When expr9 is a | Funcref | type variable, invoke the function it refers to.
1371
+ When expr10 is a | Funcref | type variable, invoke the function it refers to.
1351
1372
1352
1373
1353
- expr9 ->name([args]) method call *method* *->*
1354
- expr9 ->{lambda} ([args])
1374
+ expr10 ->name([args]) method call *method* *->*
1375
+ expr10 ->{lambda} ([args])
1355
1376
*E260* *E276* *E1265*
1356
1377
For methods that are also available as global functions this is the same as: >
1357
- name(expr9 [, args])
1358
- There can also be methods specifically for the type of "expr9 ".
1378
+ name(expr10 [, args])
1379
+ There can also be methods specifically for the type of "expr10 ".
1359
1380
1360
1381
This allows for chaining, passing the value that one method returns to the
1361
1382
next method: >
@@ -1364,7 +1385,7 @@ next method: >
1364
1385
Example of using a lambda: >
1365
1386
GetPercentage()->{x -> x * 100}()->printf('%d%%')
1366
1387
<
1367
- When using -> the | expr8 | operators will be applied first, thus: >
1388
+ When using -> the | expr9 | operators will be applied first, thus: >
1368
1389
-1.234->string()
1369
1390
Is equivalent to: >
1370
1391
(-1.234)->string()
@@ -1393,7 +1414,7 @@ When using the lambda form there must be no white space between the } and the
1393
1414
(.
1394
1415
1395
1416
1396
- *expr10 *
1417
+ *expr11 *
1397
1418
number
1398
1419
------
1399
1420
number number constant *expr-number*
@@ -1402,6 +1423,10 @@ number number constant *expr-number*
1402
1423
Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
1403
1424
and Octal (starting with 0, 0o or 0O).
1404
1425
1426
+ Assuming 64 bit numbers are used (see | v:numbersize | ) an unsigned number is
1427
+ truncated to 0x7fffffffffffffff or 9223372036854775807. You can use -1 to get
1428
+ 0xffffffffffffffff.
1429
+
1405
1430
*floating-point-format*
1406
1431
Floating point numbers can be written in two forms:
1407
1432
@@ -1524,7 +1549,7 @@ to be doubled. These two commands are equivalent: >
1524
1549
if a =~ '\s*'
1525
1550
1526
1551
1527
- interpolated-string *interp-string* *E256*
1552
+ interpolated-string *$quote* *interp-string* *E256*
1528
1553
--------------------
1529
1554
$"string" interpolated string constant *expr-$quote*
1530
1555
$'string' interpolated literal string constant *expr-$'*
@@ -2978,7 +3003,7 @@ The file "~/vim/bufnetfuncs.vim" should then define functions that start with
2978
3003
2979
3004
Using an autoload script ~
2980
3005
*autoload* *E746*
2981
- This is introduced in the user manual, section | 51.5 | .
3006
+ This is introduced in the user manual, section | 52.2 | .
2982
3007
2983
3008
Using a script in the "autoload" directory is simpler, but requires using
2984
3009
exactly the right file name. A function that can be autoloaded has a name
0 commit comments