Mercurial > vim
comparison runtime/doc/vim9.txt @ 23088:285cde4b8d0e v8.2.2090
patch 8.2.2090: Vim9: dict does not accept a key in quotes
Commit: https://github.com/vim/vim/commit/c5e6a7179d7dee4315b412b56e172bb1ff092d3e
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Dec 4 19:12:14 2020 +0100
patch 8.2.2090: Vim9: dict does not accept a key in quotes
Problem: Vim9: dict does not accept a key in quotes.
Solution: Recognize a key in single or double quotes.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 04 Dec 2020 19:15:03 +0100 |
parents | 29c5f168c6fd |
children | 99ef85ff1af4 |
comparison
equal
deleted
inserted
replaced
23087:ca8a14cbafb6 | 23088:285cde4b8d0e |
---|---|
1 *vim9.txt* For Vim version 8.2. Last change: 2020 Nov 25 | 1 *vim9.txt* For Vim version 8.2. Last change: 2020 Dec 04 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
434 Dictionary literals ~ | 434 Dictionary literals ~ |
435 | 435 |
436 Traditionally Vim has supported dictionary literals with a {} syntax: > | 436 Traditionally Vim has supported dictionary literals with a {} syntax: > |
437 let dict = {'key': value} | 437 let dict = {'key': value} |
438 | 438 |
439 Later it became clear that using a simple key name is very common, thus | 439 Later it became clear that using a simple text key is very common, thus |
440 literally dictionaries were introduced in a backwards compatible way: > | 440 literal dictionaries were introduced in a backwards compatible way: > |
441 let dict = #{key: value} | 441 let dict = #{key: value} |
442 | 442 |
443 However, this #{} syntax is unlike any existing language. As it appears that | 443 However, this #{} syntax is unlike any existing language. As it turns out |
444 using a literal key is much more common than using an expression, and | 444 that using a literal key is much more common than using an expression, and |
445 considering that JavaScript uses this syntax, using the {} form for dictionary | 445 considering that JavaScript uses this syntax, using the {} form for dictionary |
446 literals was considered a much more useful syntax. In Vim9 script the {} form | 446 literals is considered a much more useful syntax. In Vim9 script the {} form |
447 uses literal keys: > | 447 uses literal keys: > |
448 let dict = {key: value} | 448 let dict = {key: value} |
449 | 449 |
450 In case an expression needs to be used for the key, square brackets can be | 450 This works for alphanumeric characters, underscore and dash. If you want to |
451 used, just like in JavaScript: > | 451 use another character, use a single or double quoted string: > |
452 let dict = {'key with space': value} | |
453 let dict = {"key\twith\ttabs": value} | |
454 let dict = {'': value} # empty key | |
455 | |
456 In case the key needs to be an expression, square brackets can be used, just | |
457 like in JavaScript: > | |
452 let dict = {["key" .. nr]: value} | 458 let dict = {["key" .. nr]: value} |
453 | 459 |
454 | 460 |
455 No :xit, :t, :append, :change or :insert ~ | 461 No :xit, :t, :append, :change or :insert ~ |
456 | 462 |