1
- *eval.txt* For Vim version 8.2. Last change: 2022 Apr 17
1
+ *eval.txt* For Vim version 8.2. Last change: 2022 May 13
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -523,8 +523,8 @@ only appear once. Examples: >
523
523
A key is always a String. You can use a Number, it will be converted to a
524
524
String automatically. Thus the String '4' and the number 4 will find the same
525
525
entry. Note that the String '04' and the Number 04 are different, since the
526
- Number will be converted to the String '4'. The empty string can also be used
527
- as a key.
526
+ Number will be converted to the String '4', leading zeros are dropped. The
527
+ empty string can also be used as a key.
528
528
529
529
In | Vim9 | script literaly keys can be used if the key consists of alphanumeric
530
530
characters, underscore and dash, see | vim9-literal-dict | .
@@ -534,7 +534,8 @@ legacy script. This does require the key to consist only of ASCII letters,
534
534
digits, '-' and '_'. Example: >
535
535
:let mydict = #{zero: 0, one_key: 1, two-key: 2, 333: 3}
536
536
Note that 333 here is the string "333". Empty keys are not possible with #{}.
537
- In | Vim9 | script the #{} form cannot be used.
537
+ In | Vim9 | script the #{} form cannot be used because it can be confused with
538
+ the start of a comment.
538
539
539
540
A value can be any expression. Using a Dictionary for a value creates a
540
541
nested Dictionary: >
@@ -1533,14 +1534,22 @@ allowing the inclusion of Vim script expressions (see |expr1|). Any
1533
1534
expression returning a value can be enclosed between curly braces. The value
1534
1535
is converted to a string. All the text and results of the expressions
1535
1536
are concatenated to make a new string.
1536
-
1537
+ *E1278*
1537
1538
To include an opening brace '{' or closing brace '}' in the string content
1538
- double it.
1539
+ double it. For double quoted strings using a backslash also works. A single
1540
+ closing brace '}' will result in an error.
1539
1541
1540
1542
Examples: >
1541
1543
let your_name = input("What's your name? ")
1544
+ < What's your name? Peter ~
1545
+ >
1546
+ echo
1542
1547
echo $"Hello, {your_name}!"
1543
- echo $"The square root of 9 is {sqrt(9)}"
1548
+ < Hello, Peter! ~
1549
+ >
1550
+ echo $"The square root of {{9}} is {sqrt(9)}"
1551
+ < The square root of {9} is 3.0 ~
1552
+
1544
1553
1545
1554
option *expr-option* *E112* *E113*
1546
1555
------
@@ -2951,7 +2960,7 @@ the "autoload" directory in 'runtimepath'.
2951
2960
2952
2961
Using an autocommand ~
2953
2962
2954
- This is introduced in the user manual, section | 41.14 | .
2963
+ This is introduced in the user manual, section | 51.4 | .
2955
2964
2956
2965
The autocommand is useful if you have a plugin that is a long Vim script file.
2957
2966
You can define the autocommand and quickly quit the script with `:finish ` .
@@ -2969,7 +2978,7 @@ The file "~/vim/bufnetfuncs.vim" should then define functions that start with
2969
2978
2970
2979
Using an autoload script ~
2971
2980
*autoload* *E746*
2972
- This is introduced in the user manual, section | 41.15 | .
2981
+ This is introduced in the user manual, section | 51.5 | .
2973
2982
2974
2983
Using a script in the "autoload" directory is simpler, but requires using
2975
2984
exactly the right file name. A function that can be autoloaded has a name
@@ -3252,20 +3261,20 @@ text...
3252
3261
{endmarker} .
3253
3262
3254
3263
If "eval" is not specified, then each line of text is
3255
- used as a | literal-string | . If "eval" is specified,
3256
- then any Vim expression in the form ``= {expr }` ` is
3257
- evaluated and the result replaces the expression.
3264
+ used as a | literal-string | , except that single quotes
3265
+ doe not need to be doubled.
3266
+ If "eval" is specified, then any Vim expression in the
3267
+ form {expr} is evaluated and the result replaces the
3268
+ expression, like with | interp-string | .
3258
3269
Example where $HOME is expanded: >
3259
3270
let lines =<< trim eval END
3260
3271
some text
3261
- See the file `= $HOME` /.vimrc
3272
+ See the file { $HOME} /.vimrc
3262
3273
more text
3263
3274
END
3264
3275
< There can be multiple Vim expressions in a single line
3265
3276
but an expression cannot span multiple lines. If any
3266
3277
expression evaluation fails, then the assignment fails.
3267
- once the "`=" has been found {expr} and a backtick
3268
- must follow. {expr} cannot be empty.
3269
3278
3270
3279
{endmarker} must not contain white space.
3271
3280
{endmarker} cannot start with a lower case character.
@@ -3318,10 +3327,10 @@ text...
3318
3327
DATA
3319
3328
3320
3329
let code =<< trim eval CODE
3321
- let v = `= 10 + 20`
3322
- let h = "`= $HOME` "
3323
- let s = "`= Str1()` abc `= Str2()` "
3324
- let n = `= MyFunc(3, 4)`
3330
+ let v = { 10 + 20}
3331
+ let h = "{ $HOME} "
3332
+ let s = "{ Str1()} abc { Str2()} "
3333
+ let n = { MyFunc(3, 4)}
3325
3334
CODE
3326
3335
<
3327
3336
*E121*
@@ -3537,8 +3546,8 @@ text...
3537
3546
:for {var} in {object} *:for* *E690* *E732*
3538
3547
:endfo[r] *:endfo* *:endfor*
3539
3548
Repeat the commands between `:for ` and `:endfor ` for
3540
- each item in {object} . {object} can be a | List | or
3541
- a | Blob | . *E1177*
3549
+ each item in {object} . {object} can be a | List | ,
3550
+ a | Blob | or a | String | . *E1177*
3542
3551
3543
3552
Variable {var} is set to the value of each item.
3544
3553
In | Vim9 | script the loop variable must not have been
0 commit comments