summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-19 18:53:18 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-19 18:53:18 +0100
commit2bede173a177e227e6224a8713f5b88a38d011af (patch)
tree6e06ae9f20258220b8b41a66f915f230d7c25148 /runtime
parentee8b787bcd15f63a938243770065e704c9b5c85f (diff)
patch 8.2.2015: Vim9: literal dict #{} is not like any other languagev8.2.2015
Problem: Vim9: literal dict #{} is not like any other language. Solution: Support the JavaScript syntax.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/vim9.txt29
1 files changed, 24 insertions, 5 deletions
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index 85513739b2..b63e7194b4 100644
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -112,8 +112,7 @@ In Vi # is a command to list text with numbers. In Vim9 script you can use
101 number
To improve readability there must be a space between a command and the #
-that starts a comment. Note that #{ is the start of a dictionary, therefore
-it does not start a comment.
+that starts a comment.
Vim9 functions ~
@@ -303,8 +302,7 @@ identifier or can't be an Ex command. Examples: >
myList->add(123)
g:myList->add(123)
[1, 2, 3]->Process()
- #{a: 1, b: 2}->Process()
- {'a': 1, 'b': 2}->Process()
+ {a: 1, b: 2}->Process()
"foobar"->Process()
("foobar")->Process()
'foobar'->Process()
@@ -346,7 +344,7 @@ those cases there is no need to prefix the line with a backslash
'two',
]
And when a dict spans multiple lines: >
- var mydict = #{
+ var mydict = {
one: 1,
two: 2,
}
@@ -430,6 +428,27 @@ No curly braces expansion ~
|curly-braces-names| cannot be used.
+Dictionary literals ~
+
+Traditionally Vim has supported dictionary literals with a {} syntax: >
+ let dict = {'key': value}
+
+Later it became clear that using a simple key name is very common, thus
+literally dictionaries were introduced in a backwards compatible way: >
+ let dict = #{key: value}
+
+However, this #{} syntax is unlike any existing language. As it appears that
+using a literaly key is much more common than using an expression, and
+considering that JavaScript uses this syntax, using the {} form for dictionary
+literals was considered a much more useful syntax. In Vim9 script the {} form
+uses literal keys: >
+ let dict = {key: value}
+
+In case an expression needs to be used for the key, square brackets can be
+used, just like in JavaScript: >
+ let dict = {["key" .. nr]: value}
+
+
No :xit, :t, :append, :change or :insert ~
These commands are too easily confused with local variable names.