Mercurial > vim
comparison runtime/doc/eval.txt @ 85:fc244e0a6e7e
updated for version 7.0034
author | vimboss |
---|---|
date | Sat, 08 Jan 2005 16:08:21 +0000 |
parents | 366d9947baf2 |
children | 014ba200db86 |
comparison
equal
deleted
inserted
replaced
84:60834e43d187 | 85:fc244e0a6e7e |
---|---|
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 07 | 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 08 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
10 | 10 |
11 Note: Expression evaluation can be disabled at compile time. If this has been | 11 Note: Expression evaluation can be disabled at compile time. If this has been |
12 done, the features in this document are not available. See |+eval| and the | 12 done, the features in this document are not available. See |+eval| and the |
13 last chapter below. | 13 last chapter below. |
14 | 14 |
15 1. Variables |variables| | 15 1. Variables |variables| |
16 2. Expression syntax |expression-syntax| | 16 1.1 Variable types |
17 3. Internal variable |internal-variables| | 17 1.2 Function reference |Funcref| |
18 4. Builtin Functions |functions| | 18 1.3 List |List| |
19 5. Defining functions |user-functions| | 19 1.4 More about variables |more-variables| |
20 6. Curly braces names |curly-braces-names| | 20 2. Expression syntax |expression-syntax| |
21 7. Commands |expression-commands| | 21 3. Internal variable |internal-variables| |
22 8. Exception handling |exception-handling| | 22 4. Builtin Functions |functions| |
23 9. Examples |eval-examples| | 23 5. Defining functions |user-functions| |
24 10. No +eval feature |no-eval-feature| | 24 6. Curly braces names |curly-braces-names| |
25 11. The sandbox |eval-sandbox| | 25 7. Commands |expression-commands| |
26 8. Exception handling |exception-handling| | |
27 9. Examples |eval-examples| | |
28 10. No +eval feature |no-eval-feature| | |
29 11. The sandbox |eval-sandbox| | |
26 | 30 |
27 {Vi does not have any of these commands} | 31 {Vi does not have any of these commands} |
28 | 32 |
29 ============================================================================== | 33 ============================================================================== |
30 1. Variables *variables* | 34 1. Variables *variables* |
31 | 35 |
32 There are three types of variables: | 36 1.1 Variable types ~ |
37 | |
38 There are four types of variables: | |
33 | 39 |
34 Number a 32 bit signed number | 40 Number a 32 bit signed number |
35 String a NUL terminated string of 8-bit unsigned characters (bytes) | 41 String a NUL terminated string of 8-bit unsigned characters (bytes) |
36 Funcref a reference to a function |Funcref| | 42 Funcref a reference to a function |Funcref| |
37 List an ordered sequence of items |List| | 43 List an ordered sequence of items |List| |
65 :if "foo" | 71 :if "foo" |
66 "foo" is converted to 0, which means FALSE. To test for a non-empty string, | 72 "foo" is converted to 0, which means FALSE. To test for a non-empty string, |
67 use strlen(): > | 73 use strlen(): > |
68 :if strlen("foo") | 74 :if strlen("foo") |
69 | 75 |
70 | 76 List and Funcref types are not automatically converted. |
71 Function references ~ | 77 |
72 *Funcref* | 78 *E706* |
73 | 79 You will get an error if you try to change the type of a variable. You need |
80 to |:unlet| it first to avoid this error. String and Number are considered | |
81 equivalent though. > | |
82 :let l = "string" | |
83 :let l = 44 | |
84 :let l = [1, 2, 3] " error! | |
85 | |
86 | |
87 1.2 Function reference ~ | |
88 *Funcref* *E695* *E703* | |
74 A Funcref variable is obtained with the |function()| function. It can be used | 89 A Funcref variable is obtained with the |function()| function. It can be used |
75 in an expression to invoke the function it refers to by using it in the place | 90 in an expression to invoke the function it refers to by using it in the place |
76 of a function name, before the parenthesis around the arguments. Example: > | 91 of a function name, before the parenthesis around the arguments. Example: > |
77 | 92 |
78 :let Fn = function("MyFunc") | 93 :let Fn = function("MyFunc") |
79 :echo Fn() | 94 :echo Fn() |
80 | 95 < |
81 Note that this doesn't work with |:call|, because its argument is not an | 96 *E704* *E705* *E707* |
82 expression. | 97 A Funcref variable must start with a capital, "s:", "w:" or "b:". You cannot |
83 The name of the referenced function can be obtained with |string()|. A | 98 have both a Funcref variable and a function with the same name. |
84 Funcref variable must start with a capital, "s:", "w:" or "b:". | 99 |
85 | 100 Note that a Funcref cannot be used with |:call|, because its argument is not |
86 | 101 an expression. |
87 Lists ~ | 102 |
88 *List* | 103 The name of the referenced function can be obtained with |string()|. > |
104 :echo "The function is " . string(Myfunc) | |
105 | |
106 You can use |call()| to invoke a Funcref and use a list variable for the | |
107 arguments: > | |
108 :let r = call(Myfunc, mylist) | |
109 | |
110 | |
111 1.3 List ~ | |
112 *List* *E686* | |
89 A List is an ordered sequence of items. An item can be of any type. Items | 113 A List is an ordered sequence of items. An item can be of any type. Items |
90 can be accessed by their index number. Items can be added and removed at any | 114 can be accessed by their index number. Items can be added and removed at any |
91 position in the sequence. | 115 position in the sequence. |
92 | 116 |
117 | |
118 List creation ~ | |
119 *E696* *E697* | |
93 A List is created with a comma separated list of items in square brackets. | 120 A List is created with a comma separated list of items in square brackets. |
94 Example: > | 121 Examples: > |
95 :let mylist = [1, 'two', 3, "four"] | 122 :let mylist = [1, two, 3, "four"] |
123 :let emptylist = [] | |
96 | 124 |
97 An item can be any expression. Using a List for an item creates a | 125 An item can be any expression. Using a List for an item creates a |
98 two-dimensional List: > | 126 nested List: > |
99 :let mylist = [[11, 12], [21, 22], [31, 32]] | 127 :let nestlist = [[11, 12], [21, 22], [31, 32]] |
100 | 128 |
101 An extra comma after the last item is ignored. | 129 An extra comma after the last item is ignored. |
102 | 130 |
131 | |
132 List index ~ | |
133 *list-index* *E684* | |
103 An item in the List can be accessed by putting the index in square brackets | 134 An item in the List can be accessed by putting the index in square brackets |
104 after the List: > | 135 after the List. Indexes are zero-based, thus the first item has index zero. > |
136 :let item = mylist[0] " get the first item: 1 | |
105 :let item = mylist[2] " get the third item: 3 | 137 :let item = mylist[2] " get the third item: 3 |
106 < | 138 |
107 *list-index* | 139 When the item is a list again this can be repeated: > |
108 Indexes are zero-based, thus the first item has index zero. A negative index | 140 :let item = nestlist[0][1] " get the first list, second item: 12 |
109 is counted from the end. Index -1 refers to the last item in the List, -2 to | 141 < |
110 the last but one item, etc. > | 142 A negative index is counted from the end. Index -1 refers to the last item in |
143 the List, -2 to the last but one item, etc. > | |
111 :let last = mylist[-1] " get the last item: "four" | 144 :let last = mylist[-1] " get the last item: "four" |
145 | |
146 To avoid an error for an invalid index use the |get()| function. When an item | |
147 is not available it returns zero, unless you specify a default value: > | |
148 :echo get(mylist, idx) | |
149 :echo get(mylist, idx, "NONE") | |
150 | |
151 | |
152 List concatenation ~ | |
153 | |
154 Two lists can be concatenated with the "+" operator: > | |
155 :let longlist = mylist + [5, 6] | |
156 | |
157 To prepend or append an item turn the item into a list by putting [] around | |
158 it. To change a list in-place see |list-modification| below. | |
159 | |
160 | |
161 Sublist ~ | |
112 | 162 |
113 A part of the List can be obtained by specifying the first and last index, | 163 A part of the List can be obtained by specifying the first and last index, |
114 separated by a colon in square brackets: > | 164 separated by a colon in square brackets: > |
115 :let smalllist = mylist[2:-1] " get List [3, "four"] | 165 :let shortlist = mylist[2:-1] " get List [3, "four"] |
116 | 166 |
117 Omitting the first index is similar to zero. Omitting the last index is | 167 Omitting the first index is similar to zero. Omitting the last index is |
118 similar to -1. The difference is that there is no error if the items are not | 168 similar to -1. The difference is that there is no error if the items are not |
119 available. > | 169 available. > |
120 :let endlist = [2:] " from item 2 to the end: [3, "four"] | 170 :let endlist = [2:] " from item 2 to the end: [3, "four"] |
121 :let shortlist = [1:1] " List with one item: ['two'] | 171 :let shortlist = [2:2] " List with one item: [3] |
122 :let otherlist = [:] " make a copy | 172 :let otherlist = [:] " make a copy of the List |
123 | 173 |
124 | 174 |
125 More about variables ~ | 175 List identity ~ |
126 | 176 |
177 When variable "aa" is a list and you assign it to another variable "bb", both | |
178 variables refer to the same list. Thus changing the list "aa" will also | |
179 change "bb": > | |
180 :let aa = [1, 2, 3] | |
181 :let bb = aa | |
182 :call add(aa, 4) | |
183 :echo bb | |
184 [1, 2, 3, 4] | |
185 | |
186 Making a copy of a list is done with the |copy()| function. Using [:] also | |
187 works, as explained above. This creates a shallow copy of the list: Changing | |
188 a list in the list will also change the copied list: > | |
189 :let aa = [[1, 'a'], 2, 3] | |
190 :let bb = copy(aa) | |
191 :let aa = aa + [4] | |
192 :let aa[0][1] = 'aaa' | |
193 :echo aa | |
194 [[1, aaa], 2, 3, 4] | |
195 :echo bb | |
196 [[1, aaa], 2, 3] | |
197 | |
198 To make a completely independent list use |deepcopy()|. This also copies the | |
199 values in the list, recursively. | |
200 | |
201 The operator "is" can be used to check if two variables refer to the same | |
202 list. "isnot" does the opposite. In contrast "==" compares if two lists have | |
203 the same value. | |
204 | |
205 | |
206 List unpack ~ | |
207 | |
208 To unpack the items in a list to individual variables, put the variables in | |
209 square brackets, like list items: > | |
210 :let [var1, var2] = mylist | |
211 | |
212 When the number of variables does not match the number of items in the list | |
213 this produces an error. To handle any extra items from the list append ";" | |
214 and a variable name: > | |
215 :let [var1, var2; rest] = mylist | |
216 | |
217 This works like: > | |
218 :let var1 = mylist[0] | |
219 :let var2 = mylist[1] | |
220 :let rest = mjlist[2:] | |
221 | |
222 Except that there is no error if there are only two items. "rest" will be an | |
223 empty list then. | |
224 | |
225 | |
226 List modification ~ | |
227 *list-modification* | |
228 To change a specific item of a list use |:let|: > | |
229 :let list[4] = "four" | |
230 :let listlist[0][3] = item | |
231 | |
232 Adding and removing items from a list is done with functions. Here are a few | |
233 examples: > | |
234 :call insert(list, 'a') " prepend item 'a' | |
235 :call insert(list, 'a', 3) " insert item 'a' before list[3] | |
236 :call add(list, "new") " append String item | |
237 :call add(list, [1, 2]) " append List as one new item | |
238 :call extend(list, [1, 2]) " extend the list with two more items | |
239 :let i = remove(list, 3) " remove item 3 | |
240 :let l = remove(list, 3, -1) " remove items 3 to last item | |
241 | |
242 | |
243 For loop ~ | |
244 | |
245 The |:for| loop executes commands for each item in a list. Example: > | |
246 :for i in mylist | |
247 : call Doit(i) | |
248 :endfor | |
249 | |
250 This works like: > | |
251 :let index = 0 | |
252 :while index < len(mylist) | |
253 : let i = mylist[index] | |
254 : :call Doit(i) | |
255 : let index = index + 1 | |
256 :endwhile | |
257 | |
258 Note that all items in the list should be of the same type, otherwise this | |
259 results in an error. To avoid this |:unlet| the variable at the end of the | |
260 loop. | |
261 | |
262 Just like the |:let| command, |:for| also accepts a list of variables. This | |
263 requires the argument to be a list of lists. > | |
264 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]] | |
265 : call Doit(lnum, col) | |
266 :endfor | |
267 | |
268 This works like a |:let| command is done for each list item. Again, the types | |
269 must remain the same to avoid an error. | |
270 | |
271 It is also possible to put remaining items in a list: > | |
272 :for [i, j; rest] in listlist | |
273 : call Doit(i, j) | |
274 : if !empty(rest) | |
275 : echo "remainder: " . string(rest) | |
276 : endif | |
277 :endfor | |
278 | |
279 | |
280 List functions ~ | |
281 | |
282 Functions that are useful with a List: > | |
283 :let r = call(funcname, list) " invoke a function with argument list | |
284 :if empty(list) " check if list is empty | |
285 :let l = len(list) " number of items in a list | |
286 :let xs = count(list, 'x') " count occurrences of a value | |
287 :let i = index(list, 'x') " find a value | |
288 :let lines = getline(1, 10) " get ten text lines from buffer | |
289 :call append('$', lines) " append text lines in buffer | |
290 :let list = str2list("a b c") " create list from items in a string | |
291 :let s = string() " String representation of a list | |
292 | |
293 | |
294 1.4 More about variables ~ | |
295 *more-variables* | |
127 If you need to know the type of a variable or expression, use the |type()| | 296 If you need to know the type of a variable or expression, use the |type()| |
128 function. | 297 function. |
129 | 298 |
130 When the '!' flag is included in the 'viminfo' option, global variables that | 299 When the '!' flag is included in the 'viminfo' option, global variables that |
131 start with an uppercase letter, and don't contain a lowercase letter, are | 300 start with an uppercase letter, and don't contain a lowercase letter, are |
301 Examples: | 470 Examples: |
302 "abc" ==# "Abc" evaluates to 0 | 471 "abc" ==# "Abc" evaluates to 0 |
303 "abc" ==? "Abc" evaluates to 1 | 472 "abc" ==? "Abc" evaluates to 1 |
304 "abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise | 473 "abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise |
305 | 474 |
475 *E691* *E692* | |
306 A List can only be compared with a List and only "equal", "not equal" and "is" | 476 A List can only be compared with a List and only "equal", "not equal" and "is" |
307 can be used. This compares the values of the list, recursively. Ignoring | 477 can be used. This compares the values of the list, recursively. Ignoring |
308 case means case is ignored when comparing item values. | 478 case means case is ignored when comparing item values. |
309 | 479 |
480 *E693* *E694* | |
310 A Funcref can only be compared with a Funcref and only "equal" and "not equal" | 481 A Funcref can only be compared with a Funcref and only "equal" and "not equal" |
311 can be used. Case is never ignored. | 482 can be used. Case is never ignored. |
312 | 483 |
313 When using "is" or "isnot" with a List this checks if the expressions are | 484 When using "is" or "isnot" with a List this checks if the expressions are |
314 referring to the same List instance. A copy of a List is different from the | 485 referring to the same List instance. A copy of a List is different from the |
964 deepcopy( {expr}) any make a full copy of {expr} | 1135 deepcopy( {expr}) any make a full copy of {expr} |
965 delete( {fname}) Number delete file {fname} | 1136 delete( {fname}) Number delete file {fname} |
966 did_filetype() Number TRUE if FileType autocommand event used | 1137 did_filetype() Number TRUE if FileType autocommand event used |
967 diff_filler( {lnum}) Number diff filler lines about {lnum} | 1138 diff_filler( {lnum}) Number diff filler lines about {lnum} |
968 diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col} | 1139 diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col} |
1140 empty( {expr}) Number TRUE if {expr} is empty | |
969 escape( {string}, {chars}) String escape {chars} in {string} with '\' | 1141 escape( {string}, {chars}) String escape {chars} in {string} with '\' |
970 eventhandler( ) Number TRUE if inside an event handler | 1142 eventhandler( ) Number TRUE if inside an event handler |
971 executable( {expr}) Number 1 if executable {expr} exists | 1143 executable( {expr}) Number 1 if executable {expr} exists |
972 exists( {expr}) Number TRUE if {expr} exists | 1144 exists( {expr}) Number TRUE if {expr} exists |
973 expand( {expr}) String expand special keywords in {expr} | 1145 expand( {expr}) String expand special keywords in {expr} |
1104 List. Examples: > | 1276 List. Examples: > |
1105 :let alist = add([1, 2, 3], item) | 1277 :let alist = add([1, 2, 3], item) |
1106 :call add(mylist, "woodstock") | 1278 :call add(mylist, "woodstock") |
1107 < Note that when {expr} is a List it is appended as a single | 1279 < Note that when {expr} is a List it is appended as a single |
1108 item. Use |extend()| to concatenate Lists. | 1280 item. Use |extend()| to concatenate Lists. |
1281 Use |insert()| to add an item at another position. | |
1109 | 1282 |
1110 | 1283 |
1111 append({lnum}, {expr}) *append()* | 1284 append({lnum}, {expr}) *append()* |
1112 When {expr} is a List: Append each item of the list as a text | 1285 When {expr} is a List: Append each item of the list as a text |
1113 line below line {lnum} in the current buffer. | 1286 line below line {lnum} in the current buffer. |
1271 echo strpart(s, 0, byteidx(s, 1)) | 1444 echo strpart(s, 0, byteidx(s, 1)) |
1272 < If there are less than {nr} characters -1 is returned. | 1445 < If there are less than {nr} characters -1 is returned. |
1273 If there are exactly {nr} characters the length of the string | 1446 If there are exactly {nr} characters the length of the string |
1274 is returned. | 1447 is returned. |
1275 | 1448 |
1276 call({func}, {arglist}) *call()* | 1449 call({func}, {arglist}) *call()* *E699* |
1277 Call function {func} with the items in List {arglist} as | 1450 Call function {func} with the items in List {arglist} as |
1278 arguments. | 1451 arguments. |
1279 {func} can either be a Funcref or the name of a function. | 1452 {func} can either be a Funcref or the name of a function. |
1280 a:firstline and a:lastline are set to the cursor line. | 1453 a:firstline and a:lastline are set to the cursor line. |
1281 Returns the return value of the called function. | 1454 Returns the return value of the called function. |
1435 the cursor will be positioned at the last character in the | 1608 the cursor will be positioned at the last character in the |
1436 line. | 1609 line. |
1437 If {col} is zero, the cursor will stay in the current column. | 1610 If {col} is zero, the cursor will stay in the current column. |
1438 | 1611 |
1439 | 1612 |
1440 deepcopy({expr}) *deepcopy()* | 1613 deepcopy({expr}) *deepcopy()* *E698* |
1441 Make a copy of {expr}. For Numbers and Strings this isn't | 1614 Make a copy of {expr}. For Numbers and Strings this isn't |
1442 different from using {expr} directly. | 1615 different from using {expr} directly. |
1443 When {expr} is a List a full copy is created. This means | 1616 When {expr} is a List a full copy is created. This means |
1444 that the original List can be changed without changing the | 1617 that the original List can be changed without changing the |
1445 copy, and vise versa. When an item is a List, a copy for it | 1618 copy, and vise versa. When an item is a List, a copy for it |
1481 line, "'m" mark m, etc. | 1654 line, "'m" mark m, etc. |
1482 {col} is 1 for the leftmost column, {lnum} is 1 for the first | 1655 {col} is 1 for the leftmost column, {lnum} is 1 for the first |
1483 line. | 1656 line. |
1484 The highlight ID can be used with |synIDattr()| to obtain | 1657 The highlight ID can be used with |synIDattr()| to obtain |
1485 syntax information about the highlighting. | 1658 syntax information about the highlighting. |
1659 | |
1660 empty({expr}) *empty()* | |
1661 Return the Number 1 if {expr} is empty, zero otherwise. | |
1662 A List is empty when it does not have any items. | |
1663 A Number is empty when its value is zero. | |
1664 For a long List this is much faster then comparing the length | |
1665 with zero. | |
1486 | 1666 |
1487 escape({string}, {chars}) *escape()* | 1667 escape({string}, {chars}) *escape()* |
1488 Escape the characters in {chars} that occur in {string} with a | 1668 Escape the characters in {chars} that occur in {string} with a |
1489 backslash. Example: > | 1669 backslash. Example: > |
1490 :echo escape('c:\program files\vim', ' \') | 1670 :echo escape('c:\program files\vim', ' \') |
1752 |remote_foreground()| instead. | 1932 |remote_foreground()| instead. |
1753 {only in the Win32, Athena, Motif and GTK GUI versions and the | 1933 {only in the Win32, Athena, Motif and GTK GUI versions and the |
1754 Win32 console version} | 1934 Win32 console version} |
1755 | 1935 |
1756 | 1936 |
1757 function({name}) *function()* | 1937 function({name}) *function()* *E700* |
1758 Return a Funcref variable that refers to function {name}. | 1938 Return a Funcref variable that refers to function {name}. |
1759 {name} can be a user defined function or an internal function. | 1939 {name} can be a user defined function or an internal function. |
1760 | 1940 |
1761 | 1941 |
1762 get({list}, {idx} [, {default}]) *get* | 1942 get({list}, {idx} [, {default}]) *get* |
2258 The result is a Number, which is non-zero when a directory | 2438 The result is a Number, which is non-zero when a directory |
2259 with the name {directory} exists. If {directory} doesn't | 2439 with the name {directory} exists. If {directory} doesn't |
2260 exist, or isn't a directory, the result is FALSE. {directory} | 2440 exist, or isn't a directory, the result is FALSE. {directory} |
2261 is any expression, which is used as a String. | 2441 is any expression, which is used as a String. |
2262 | 2442 |
2263 *len()* | 2443 *len()* *E701* |
2264 len({expr}) The result is a Number, which is the length of the argument. | 2444 len({expr}) The result is a Number, which is the length of the argument. |
2265 When {expr} is a String or a Number the length in bytes is | 2445 When {expr} is a String or a Number the length in bytes is |
2266 used, as with |strlen()|. | 2446 used, as with |strlen()|. |
2267 When {expr} is a List the number of items in the List is | 2447 When {expr} is a List the number of items in the List is |
2268 returned. | 2448 returned. |
2856 removed when "dir" is a symbolic link within the same | 3036 removed when "dir" is a symbolic link within the same |
2857 directory. In order to resolve all the involved symbolic | 3037 directory. In order to resolve all the involved symbolic |
2858 links before simplifying the path name, use |resolve()|. | 3038 links before simplifying the path name, use |resolve()|. |
2859 | 3039 |
2860 | 3040 |
2861 sort({list} [, {func}]) *sort()* | 3041 sort({list} [, {func}]) *sort()* *E702* |
2862 Sort the items in {list} in-place. Returns {list}. If you | 3042 Sort the items in {list} in-place. Returns {list}. If you |
2863 want a list to remain unmodified make a copy first: > | 3043 want a list to remain unmodified make a copy first: > |
2864 :let sortedlist = sort(copy(mylist)) | 3044 :let sortedlist = sort(copy(mylist)) |
2865 < Uses the string representation of each item to sort on. | 3045 < Uses the string representation of each item to sort on. |
2866 When {func} is given and it is one then case is ignored. | 3046 When {func} is given and it is one then case is ignored. |
2920 {expr} type result ~ | 3100 {expr} type result ~ |
2921 String identical | 3101 String identical |
2922 Number decimal representation | 3102 Number decimal representation |
2923 Funcref name of the function | 3103 Funcref name of the function |
2924 List "[item, item]" form | 3104 List "[item, item]" form |
3105 Note that string values are not in quotes, thus the result | |
3106 can't be parsed back to a List. | |
2925 | 3107 |
2926 *strlen()* | 3108 *strlen()* |
2927 strlen({expr}) The result is a Number, which is the length of the String | 3109 strlen({expr}) The result is a Number, which is the length of the String |
2928 {expr} in bytes. If you want to count the number of | 3110 {expr} in bytes. If you want to count the number of |
2929 multi-byte characters use something like this: > | 3111 multi-byte characters use something like this: > |
3650 Set internal variable {var-name} to the result of the | 3832 Set internal variable {var-name} to the result of the |
3651 expression {expr1}. The variable will get the type | 3833 expression {expr1}. The variable will get the type |
3652 from the {expr}. If {var-name} didn't exist yet, it | 3834 from the {expr}. If {var-name} didn't exist yet, it |
3653 is created. | 3835 is created. |
3654 | 3836 |
3837 :let {var-name}[{idx}] = {expr1} *E689* | |
3838 Set a list item to the result of the expression | |
3839 {expr1}. {var-name} must refer to a list and {idx} | |
3840 must be a valid index in that list. For nested list | |
3841 the index can be repeated. | |
3842 This cannot be used to add an item to a list. | |
3843 | |
3655 :let ${env-name} = {expr1} *:let-environment* *:let-$* | 3844 :let ${env-name} = {expr1} *:let-environment* *:let-$* |
3656 Set environment variable {env-name} to the result of | 3845 Set environment variable {env-name} to the result of |
3657 the expression {expr1}. The type is always String. | 3846 the expression {expr1}. The type is always String. |
3658 | 3847 |
3659 :let @{reg-name} = {expr1} *:let-register* *:let-@* | 3848 :let @{reg-name} = {expr1} *:let-register* *:let-@* |
3686 | 3875 |
3687 :let &g:{option-name} = {expr1} | 3876 :let &g:{option-name} = {expr1} |
3688 Like above, but only set the global value of an option | 3877 Like above, but only set the global value of an option |
3689 (if there is one). Works like |:setglobal|. | 3878 (if there is one). Works like |:setglobal|. |
3690 | 3879 |
3691 :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* | 3880 :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* |
3692 {expr1} must evaluate to a List. The first item in | 3881 {expr1} must evaluate to a List. The first item in |
3693 the list is assigned to {name1}, the second item to | 3882 the list is assigned to {name1}, the second item to |
3694 {name2}, etc. | 3883 {name2}, etc. |
3695 The number of names must match the number of items in | 3884 The number of names must match the number of items in |
3696 the List. | 3885 the List. |
3775 :endwhile | 3964 :endwhile |
3776 < | 3965 < |
3777 NOTE: The ":append" and ":insert" commands don't work | 3966 NOTE: The ":append" and ":insert" commands don't work |
3778 properly inside a :while" and ":for" loop. | 3967 properly inside a :while" and ":for" loop. |
3779 | 3968 |
3780 :for {var} in {list} *:for* | 3969 :for {var} in {list} *:for* *E690* |
3781 :endfo[r] *:endfo* *:endfor* | 3970 :endfo[r] *:endfo* *:endfor* |
3782 Repeat the commands between ":for" and ":endfor" for | 3971 Repeat the commands between ":for" and ":endfor" for |
3783 each item in {list}. variable {var} is set to the | 3972 each item in {list}. variable {var} is set to the |
3784 value of each item. | 3973 value of each item. |
3785 When an error is detected for a command inside the | 3974 When an error is detected for a command inside the |