Mercurial > vim
comparison runtime/doc/eval.txt @ 34293:6d00518cb316
runtime(doc): further improve docs about List/Blob += operator
Commit: https://github.com/vim/vim/commit/b8170143c8f8a115b5be59a94d10f931d3cd567c
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Feb 8 11:21:44 2024 +0100
runtime(doc): further improve docs about List/Blob += operator
closes: https://github.com/vim/vim/issues/13990
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 08 Feb 2024 11:30:03 +0100 |
parents | 167d80fce1b1 |
children | c7680d286e1f |
comparison
equal
deleted
inserted
replaced
34292:8be07a64e2c3 | 34293:6d00518cb316 |
---|---|
1 *eval.txt* For Vim version 9.1. Last change: 2024 Feb 07 | 1 *eval.txt* For Vim version 9.1. Last change: 2024 Feb 08 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
301 | 301 |
302 List concatenation ~ | 302 List concatenation ~ |
303 *list-concatenation* | 303 *list-concatenation* |
304 Two lists can be concatenated with the "+" operator: > | 304 Two lists can be concatenated with the "+" operator: > |
305 :let longlist = mylist + [5, 6] | 305 :let longlist = mylist + [5, 6] |
306 A list can be concatenated with another one in place using the "+=" operator or |extend()|: > | 306 :let longlist = [5, 6] + mylist |
307 To prepend or append an item, turn it into a list by putting [] around it. | |
308 | |
309 A list can be concatenated with another one in-place using |:let+=| or | |
310 |extend()|: > | |
307 :let mylist += [7, 8] | 311 :let mylist += [7, 8] |
308 :call extend(mylist, [7, 8]) | 312 :call extend(mylist, [7, 8]) |
309 | 313 < |
310 To prepend or append an item, turn the item into a list by putting [] around | 314 See |list-modification| below for more about changing a list in-place. |
311 it. To change a list in-place, refer to |list-modification| below. | |
312 | 315 |
313 | 316 |
314 Sublist ~ | 317 Sublist ~ |
315 *sublist* | 318 *sublist* |
316 A part of the List can be obtained by specifying the first and last index, | 319 A part of the List can be obtained by specifying the first and last index, |
425 | 428 |
426 To change part of a list you can specify the first and last item to be | 429 To change part of a list you can specify the first and last item to be |
427 modified. The value must at least have the number of items in the range: > | 430 modified. The value must at least have the number of items in the range: > |
428 :let list[3:5] = [3, 4, 5] | 431 :let list[3:5] = [3, 4, 5] |
429 | 432 |
430 To add items to a List in-place, you can use the += operator | 433 To add items to a List in-place, you can use |:let+=| (|list-concatenation|): > |
431 |list-concatenation|: > | |
432 :let listA = [1, 2] | 434 :let listA = [1, 2] |
433 :let listA += [3, 4] | 435 :let listA += [3, 4] |
434 < | 436 < |
435 When two variables refer to the same List, changing one List in-place will | 437 When two variables refer to the same List, changing one List in-place will |
436 cause the referenced List to be changed in-place: > | 438 cause the referenced List to be changed in-place: > |
758 :endfor | 760 :endfor |
759 This calls Doit() with 0x11, 0x22 and 0x33. | 761 This calls Doit() with 0x11, 0x22 and 0x33. |
760 | 762 |
761 | 763 |
762 Blob concatenation ~ | 764 Blob concatenation ~ |
763 | 765 *blob-concatenation* |
764 Two blobs can be concatenated with the "+" operator: > | 766 Two blobs can be concatenated with the "+" operator: > |
765 :let longblob = myblob + 0z4455 | 767 :let longblob = myblob + 0z4455 |
768 :let longblob = 0z4455 + myblob | |
769 < | |
770 A blob can be concatenated with another one in-place using |:let+=|: > | |
766 :let myblob += 0z6677 | 771 :let myblob += 0z6677 |
767 | 772 < |
768 To change a blob in-place see |blob-modification| below. | 773 See |blob-modification| below for more about changing a blob in-place. |
769 | 774 |
770 | 775 |
771 Part of a blob ~ | 776 Part of a blob ~ |
772 | 777 |
773 A part of the Blob can be obtained by specifying the first and last index, | 778 A part of the Blob can be obtained by specifying the first and last index, |
806 | 811 |
807 To change part of a blob you can specify the first and last byte to be | 812 To change part of a blob you can specify the first and last byte to be |
808 modified. The value must have the same number of bytes in the range: > | 813 modified. The value must have the same number of bytes in the range: > |
809 :let blob[3:5] = 0z334455 | 814 :let blob[3:5] = 0z334455 |
810 | 815 |
816 To add items to a Blob in-place, you can use |:let+=| (|blob-concatenation|): > | |
817 :let blobA = 0z1122 | |
818 :let blobA += 0z3344 | |
819 < | |
820 When two variables refer to the same Blob, changing one Blob in-place will | |
821 cause the referenced Blob to be changed in-place: > | |
822 :let blobA = 0z1122 | |
823 :let blobB = blobA | |
824 :let blobB += 0z3344 | |
825 :echo blobA | |
826 0z11223344 | |
827 < | |
811 You can also use the functions |add()|, |remove()| and |insert()|. | 828 You can also use the functions |add()|, |remove()| and |insert()|. |
812 | 829 |
813 | 830 |
814 Blob identity ~ | 831 Blob identity ~ |
815 | 832 |
2822 :let {var} %= {expr1} Like ":let {var} = {var} % {expr1}". | 2839 :let {var} %= {expr1} Like ":let {var} = {var} % {expr1}". |
2823 :let {var} .= {expr1} Like ":let {var} = {var} . {expr1}". | 2840 :let {var} .= {expr1} Like ":let {var} = {var} . {expr1}". |
2824 :let {var} ..= {expr1} Like ":let {var} = {var} .. {expr1}". | 2841 :let {var} ..= {expr1} Like ":let {var} = {var} .. {expr1}". |
2825 These fail if {var} was not set yet and when the type | 2842 These fail if {var} was not set yet and when the type |
2826 of {var} and {expr1} don't fit the operator. | 2843 of {var} and {expr1} don't fit the operator. |
2844 `+=` modifies a |List| or a |Blob| in-place instead of | |
2845 creating a new one. | |
2827 `.=` is not supported with Vim script version 2 and | 2846 `.=` is not supported with Vim script version 2 and |
2828 later, see |vimscript-version|. | 2847 later, see |vimscript-version|. |
2829 | 2848 |
2830 | 2849 |
2831 :let ${env-name} = {expr1} *:let-environment* *:let-$* | 2850 :let ${env-name} = {expr1} *:let-environment* *:let-$* |