Mercurial > vim
comparison runtime/doc/eval.txt @ 99:04f2e519ab18
updated for version 7.0038
author | vimboss |
---|---|
date | Fri, 14 Jan 2005 21:48:43 +0000 |
parents | a2081e6febb8 |
children | 0aa0e89bfd5f |
comparison
equal
deleted
inserted
replaced
98:98435a8ddb09 | 99:04f2e519ab18 |
---|---|
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 11 | 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 14 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
7 Expression evaluation *expression* *expr* *E15* *eval* | 7 Expression evaluation *expression* *expr* *E15* *eval* |
8 | 8 |
9 Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|. | 9 Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|. |
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 |
13 last chapter below. | 13 |no-eval-feature|. |
14 | 14 |
15 1. Variables |variables| | 15 1. Variables |variables| |
16 1.1 Variable types | 16 1.1 Variable types |
17 1.2 Function references |Funcref| | 17 1.2 Function references |Funcref| |
18 1.3 Lists |List| | 18 1.3 Lists |List| |
19 1.4 More about variables |more-variables| | 19 1.4 Dictionaries |Dictionaries| |
20 1.5 More about variables |more-variables| | |
20 2. Expression syntax |expression-syntax| | 21 2. Expression syntax |expression-syntax| |
21 3. Internal variable |internal-variables| | 22 3. Internal variable |internal-variables| |
22 4. Builtin Functions |functions| | 23 4. Builtin Functions |functions| |
23 5. Defining functions |user-functions| | 24 5. Defining functions |user-functions| |
24 6. Curly braces names |curly-braces-names| | 25 6. Curly braces names |curly-braces-names| |
35 | 36 |
36 1.1 Variable types ~ | 37 1.1 Variable types ~ |
37 | 38 |
38 There are four types of variables: | 39 There are four types of variables: |
39 | 40 |
40 Number a 32 bit signed number | 41 Number A 32 bit signed number. |
41 String a NUL terminated string of 8-bit unsigned characters (bytes) | 42 Examples: -123 0x10 0177 |
42 Funcref a reference to a function |Funcref| | 43 |
43 List an ordered sequence of items |List| | 44 String A NUL terminated string of 8-bit unsigned characters (bytes). |
45 Examples: "ab\txx\"--" 'x-z''a,c' | |
46 | |
47 Funcref A reference to a function |Funcref|. | |
48 Example: function("strlen") | |
49 | |
50 List An ordered sequence of items |List|. | |
51 Example: [1, 2, ['a', 'b']] | |
44 | 52 |
45 The Number and String types are converted automatically, depending on how they | 53 The Number and String types are converted automatically, depending on how they |
46 are used. | 54 are used. |
47 | 55 |
48 Conversion from a Number to a String is by making the ASCII representation of | 56 Conversion from a Number to a String is by making the ASCII representation of |
76 List and Funcref types are not automatically converted. | 84 List and Funcref types are not automatically converted. |
77 | 85 |
78 *E706* | 86 *E706* |
79 You will get an error if you try to change the type of a variable. You need | 87 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 | 88 to |:unlet| it first to avoid this error. String and Number are considered |
81 equivalent though. > | 89 equivalent though. Consider this sequence of commands: > |
82 :let l = "string" | 90 :let l = "string" |
83 :let l = 44 " changes type from String to Number | 91 :let l = 44 " changes type from String to Number |
84 :let l = [1, 2, 3] " error! | 92 :let l = [1, 2, 3] " error! |
85 | 93 |
86 | 94 |
169 available. > | 177 available. > |
170 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"] | 178 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"] |
171 :let shortlist = mylist[2:2] " List with one item: [3] | 179 :let shortlist = mylist[2:2] " List with one item: [3] |
172 :let otherlist = mylist[:] " make a copy of the List | 180 :let otherlist = mylist[:] " make a copy of the List |
173 | 181 |
182 The second index can be just before the first index. In that case the result | |
183 is an empty list. If the second index is lower, this results in an error. > | |
184 :echo mylist[2:1] " result: [] | |
185 :echo mylist[2:0] " error! | |
186 | |
174 | 187 |
175 List identity ~ | 188 List identity ~ |
176 | 189 *list-identity* |
177 When variable "aa" is a list and you assign it to another variable "bb", both | 190 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 | 191 variables refer to the same list. Thus changing the list "aa" will also |
179 change "bb": > | 192 change "bb": > |
180 :let aa = [1, 2, 3] | 193 :let aa = [1, 2, 3] |
181 :let bb = aa | 194 :let bb = aa |
246 :call add(list, "new") " append String item | 259 :call add(list, "new") " append String item |
247 :call add(list, [1, 2]) " append List as one new item | 260 :call add(list, [1, 2]) " append List as one new item |
248 :call extend(list, [1, 2]) " extend the list with two more items | 261 :call extend(list, [1, 2]) " extend the list with two more items |
249 :let i = remove(list, 3) " remove item 3 | 262 :let i = remove(list, 3) " remove item 3 |
250 :let l = remove(list, 3, -1) " remove items 3 to last item | 263 :let l = remove(list, 3, -1) " remove items 3 to last item |
251 :call filter(list, #& =~ 'x'#) " remove items with an 'x' | 264 :call filter(list, '& =~ "x"') " remove items with an 'x' |
252 | 265 |
253 Changing the oder of items in a list: > | 266 Changing the oder of items in a list: > |
254 :call sort(list) " sort a list alphabetically | 267 :call sort(list) " sort a list alphabetically |
255 :call reverse(list) " reverse the order of items | 268 :call reverse(list) " reverse the order of items |
256 | 269 |
301 Functions that are useful with a List: > | 314 Functions that are useful with a List: > |
302 :let r = call(funcname, list) " call a function with an argument list | 315 :let r = call(funcname, list) " call a function with an argument list |
303 :if empty(list) " check if list is empty | 316 :if empty(list) " check if list is empty |
304 :let l = len(list) " number of items in a list | 317 :let l = len(list) " number of items in a list |
305 :let big = max(list) " maximum value in a list | 318 :let big = max(list) " maximum value in a list |
306 :let small = min(list) " minumum value in a list | 319 :let small = min(list) " minimum value in a list |
307 :let xs = count(list, 'x') " count nr of times 'x' appears in list | 320 :let xs = count(list, 'x') " count nr of times 'x' appears in list |
308 :let i = index(list, 'x') " index of first 'x' in list | 321 :let i = index(list, 'x') " index of first 'x' in list |
309 :let lines = getline(1, 10) " get ten text lines from buffer | 322 :let lines = getline(1, 10) " get ten text lines from buffer |
310 :call append('$', lines) " append text lines in buffer | 323 :call append('$', lines) " append text lines in buffer |
311 :let list = split("a b c") " create list from items in a string | 324 :let list = split("a b c") " create list from items in a string |
312 :let string = join(list, ', ') " create string from list items | 325 :let string = join(list, ', ') " create string from list items |
313 :let s = string() " String representation of a list | 326 :let s = string() " String representation of a list |
314 :call map(list, #'>> ' . &#) " prepend ">> " to each item | 327 :call map(list, '">> " . &') " prepend ">> " to each item |
315 | 328 |
316 | 329 |
317 1.4 More about variables ~ | 330 1.4 Dictionaries ~ |
331 *Dictionaries* | |
332 A Dictionary is an associative array: Each entry has a key and a value. The | |
333 entry can be located with the key. The entries are stored without ordering. | |
334 | |
335 | |
336 Dictionary creation ~ | |
337 | |
338 A Dictionary is created with a comma separated list of entries in curly | |
339 braces. Each entry has a key and a value, separated by a colon. Examples: > | |
340 :let mydict = {1: 'one', 2: 'two', 3: 'three'} | |
341 :let emptydict = {} | |
342 | |
343 A key is always a String. You can use a Number, it will be converted to a | |
344 String automatically. Thus the String '4' and the number 4 will find the same | |
345 entry. Note that the String '04' and the Number 04 are different, since 04 | |
346 will be converted to the String '4'. | |
347 | |
348 A value can be any expression. Using a Dictionary for an entry creates a | |
349 nested Dictionary: > | |
350 :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}} | |
351 | |
352 An extra comma after the last entry is ignored. | |
353 | |
354 | |
355 Accessing entries ~ | |
356 | |
357 The normal way to access an entry is by putting the key in square brackets: > | |
358 :let val = mydict["one"] | |
359 :let mydict["four"] = 4 | |
360 | |
361 You can add new entries to an existing Dictionary this way. | |
362 | |
363 For keys that consist entirely of letters, digits and underscore the following | |
364 form can be used |expr-entry|: > | |
365 :let val = mydict.one | |
366 :let mydict.four = 4 | |
367 | |
368 Since an entry can be any type, also a List and a Dictionary, the indexing and | |
369 key lookup can be repeated: > | |
370 :let dict.key[idx].key = 0 | |
371 | |
372 | |
373 Dictionary to List conversion ~ | |
374 | |
375 You may want to loop over the entries in a dictionary. For this you need to | |
376 turn the Dictionary into a List and pass it to |:for|. | |
377 | |
378 Most often you want to loop over the keys, using the |keys()| function: > | |
379 :for key in keys(mydict) | |
380 : echo key . ': ' . mydict[key] | |
381 :endfor | |
382 | |
383 The List of keys is unsorted. You may want to sort them first: > | |
384 :for key in sort(keys(mydict)) | |
385 | |
386 To loop over the values use the |values()| function: > | |
387 :for v in values(mydict) | |
388 : echo "value: " . v | |
389 :endfor | |
390 | |
391 If you want both the key and the value use the |items()| function. It returns | |
392 a List of Lists with two items: the key and the value: > | |
393 :for entry in items(mydict) | |
394 : echo entry[0] . ': ' . entry[1] | |
395 :endfor | |
396 | |
397 | |
398 Dictionary identity ~ | |
399 | |
400 Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a | |
401 Dictionary. Otherwise, assignment results in referring to the same | |
402 Dictionary: > | |
403 :let onedict = {'a': 1, 'b': 2} | |
404 :let adict = onedict | |
405 :let adict['a'] = 11 | |
406 :echo onedict['a'] | |
407 11 | |
408 | |
409 For more info see |list-identity|. | |
410 | |
411 | |
412 Dictionary modification ~ | |
413 *dict-modification* | |
414 To change an already existing entry of a Dictionary, or to add a new entry, | |
415 use |:let| this way: > | |
416 :let dict[4] = "four" | |
417 :let dict['one'] = item | |
418 | |
419 Removing an entry from a Dictionary is done with |remove()|: > | |
420 :let i = remove(dict, 'aaa') " remove item with key 'aaa' | |
421 | |
422 Merging a Dictionary with another is done with |extend()|: > | |
423 :call extend(adict, bdict) " extend adict with entries from bdict | |
424 | |
425 Weeding out entries from a Dictionary can be done with |filter()|: > | |
426 :call filter(dict '& =~ "x"') " remove entries with value 'x' | |
427 | |
428 | |
429 1.5 More about variables ~ | |
318 *more-variables* | 430 *more-variables* |
319 If you need to know the type of a variable or expression, use the |type()| | 431 If you need to know the type of a variable or expression, use the |type()| |
320 function. | 432 function. |
321 | 433 |
322 When the '!' flag is included in the 'viminfo' option, global variables that | 434 When the '!' flag is included in the 'viminfo' option, global variables that |
377 + expr7 unary plus | 489 + expr7 unary plus |
378 expr8 | 490 expr8 |
379 | 491 |
380 |expr8| expr9[expr1] byte of a String or item of a List | 492 |expr8| expr9[expr1] byte of a String or item of a List |
381 expr9[expr1 : expr2] substring of a String or sublist of a List | 493 expr9[expr1 : expr2] substring of a String or sublist of a List |
494 expr9.name entry in a Dictionary | |
382 | 495 |
383 |expr9| number number constant | 496 |expr9| number number constant |
384 "string" string constant, backslash is special | 497 "string" string constant, backslash is special |
385 'string' string constant | 498 'string' string constant, ' is doubled |
386 #string# string constant | |
387 [expr1, ...] List | 499 [expr1, ...] List |
388 &option option value | 500 &option option value |
389 (expr1) nested expression | 501 (expr1) nested expression |
390 variable internal variable | 502 variable internal variable |
391 va{ria}ble internal variable with curly braces | 503 va{ria}ble internal variable with curly braces |
605 :let item = mylist[-1] " get last item | 717 :let item = mylist[-1] " get last item |
606 | 718 |
607 Generally, if a List index is equal to or higher than the length of the List, | 719 Generally, if a List index is equal to or higher than the length of the List, |
608 or more negative than the length of the List, this results in an error. | 720 or more negative than the length of the List, this results in an error. |
609 | 721 |
722 | |
610 expr9[expr1a : expr1b] substring or sublist *expr-[:]* | 723 expr9[expr1a : expr1b] substring or sublist *expr-[:]* |
611 | 724 |
612 If expr9 is a Number or String this results in the substring with the bytes | 725 If expr9 is a Number or String this results in the substring with the bytes |
613 from expr1a to and including expr1b. expr9 is used as a String, expr1a and | 726 from expr1a to and including expr1b. expr9 is used as a String, expr1a and |
614 expr1b are used as a Number. Note that this doesn't recognize multi-byte | 727 expr1b are used as a Number. Note that this doesn't recognize multi-byte |
635 :let l = mylist[:3] " first four items | 748 :let l = mylist[:3] " first four items |
636 :let l = mylist[4:4] " List with one item | 749 :let l = mylist[4:4] " List with one item |
637 :let l = mylist[:] " shallow copy of a List | 750 :let l = mylist[:] " shallow copy of a List |
638 | 751 |
639 Using expr9[expr1] or expr9[expr1a : expr1b] on a Funcref results in an error. | 752 Using expr9[expr1] or expr9[expr1a : expr1b] on a Funcref results in an error. |
753 | |
754 | |
755 expr9.name entry in a Dictionary *expr-entry* | |
756 | |
757 If expr9 is a Dictionary and it is followed by a dot, then the following name | |
758 will be used as a key in the Dictionary. This is just like: expr9[name]. | |
759 | |
760 The name must consist of alphanumeric characters, just like a variable name, | |
761 but it may start with a number. Curly braces cannot be used. | |
762 | |
763 There must not be white space before or after the dot. | |
764 | |
765 Examples: > | |
766 :let dict = {"one": 1, 2: "two"} | |
767 :echo dict.one | |
768 :echo dict .2 | |
769 | |
770 Note that the dot is also used for String concatenation. To avoid confusion | |
771 always put spaces around the dot for String concatenation. | |
772 | |
640 | 773 |
641 *expr9* | 774 *expr9* |
642 number | 775 number |
643 ------ | 776 ------ |
644 number number constant *expr-number* | 777 number number constant *expr-number* |
681 'string' string constant *expr-'* | 814 'string' string constant *expr-'* |
682 | 815 |
683 Note that single quotes are used. | 816 Note that single quotes are used. |
684 | 817 |
685 This string is taken as it is. No backslashes are removed or have a special | 818 This string is taken as it is. No backslashes are removed or have a special |
686 meaning. A literal-string cannot contain a single quote. Use a double-quoted | 819 meaning. The only exception is that two quotes stand for one quote. |
687 string or sharp-string for that. | |
688 | 820 |
689 Single quoted strings are useful for patterns, so that backslashes do not need | 821 Single quoted strings are useful for patterns, so that backslashes do not need |
690 to be doubled. These two commands are equivalent: > | 822 to be doubled. These two commands are equivalent: > |
691 if a =~ "\\s*" | 823 if a =~ "\\s*" |
692 if a =~ '\s*' | 824 if a =~ '\s*' |
693 | |
694 | |
695 sharp-string *sharp-string* | |
696 --------------- | |
697 #string# string constant *expr-#* | |
698 | |
699 Most characters in the string are taken as-is. Only the '#' character is | |
700 special: It needs to be double to get one. | |
701 | |
702 Sharp-strings are useful when a string may contain single quotes, double | |
703 quotes and/or backslashes. | |
704 | 825 |
705 | 826 |
706 option *expr-option* *E112* *E113* | 827 option *expr-option* *E112* *E113* |
707 ------ | 828 ------ |
708 &option option value, local value if possible | 829 &option option value, local value if possible |
1234 inputsave() Number save and clear typeahead | 1355 inputsave() Number save and clear typeahead |
1235 inputsecret( {prompt} [, {text}]) String like input() but hiding the text | 1356 inputsecret( {prompt} [, {text}]) String like input() but hiding the text |
1236 insert( {list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] | 1357 insert( {list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] |
1237 isdirectory( {directory}) Number TRUE if {directory} is a directory | 1358 isdirectory( {directory}) Number TRUE if {directory} is a directory |
1238 join( {list} [, {sep}]) String join {list} items into one String | 1359 join( {list} [, {sep}]) String join {list} items into one String |
1360 keys( {dict}) List List of keys in {dict} | |
1239 len( {expr}) Number the length of {expr} | 1361 len( {expr}) Number the length of {expr} |
1240 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} | 1362 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} |
1241 libcallnr( {lib}, {func}, {arg}) Number idem, but return a Number | 1363 libcallnr( {lib}, {func}, {arg}) Number idem, but return a Number |
1242 line( {expr}) Number line nr of cursor, last line or mark | 1364 line( {expr}) Number line nr of cursor, last line or mark |
1243 line2byte( {lnum}) Number byte count of line {lnum} | 1365 line2byte( {lnum}) Number byte count of line {lnum} |
1256 min({list}) Number minumum value of items in {list} | 1378 min({list}) Number minumum value of items in {list} |
1257 mode() String current editing mode | 1379 mode() String current editing mode |
1258 nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum} | 1380 nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum} |
1259 nr2char( {expr}) String single char with ASCII value {expr} | 1381 nr2char( {expr}) String single char with ASCII value {expr} |
1260 prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum} | 1382 prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum} |
1383 range( {expr} [, {max} [, {stride}]]) | |
1384 List items from {expr} to {max} | |
1261 remote_expr( {server}, {string} [, {idvar}]) | 1385 remote_expr( {server}, {string} [, {idvar}]) |
1262 String send expression | 1386 String send expression |
1263 remote_foreground( {server}) Number bring Vim server to the foreground | 1387 remote_foreground( {server}) Number bring Vim server to the foreground |
1264 remote_peek( {serverid} [, {retvar}]) | 1388 remote_peek( {serverid} [, {retvar}]) |
1265 Number check for reply string | 1389 Number check for reply string |
1266 remote_read( {serverid}) String read reply string | 1390 remote_read( {serverid}) String read reply string |
1267 remote_send( {server}, {string} [, {idvar}]) | 1391 remote_send( {server}, {string} [, {idvar}]) |
1268 String send key sequence | 1392 String send key sequence |
1269 remove( {list}, {idx} [, {end}]) any remove items {idx}-{end} from {list} | 1393 remove( {list}, {idx} [, {end}]) any remove items {idx}-{end} from {list} |
1394 remove( {dict}, {key}) any remove entry {key} from {dict} | |
1270 rename( {from}, {to}) Number rename (move) file from {from} to {to} | 1395 rename( {from}, {to}) Number rename (move) file from {from} to {to} |
1271 repeat( {expr}, {count}) String repeat {expr} {count} times | 1396 repeat( {expr}, {count}) String repeat {expr} {count} times |
1272 resolve( {filename}) String get filename a shortcut points to | 1397 resolve( {filename}) String get filename a shortcut points to |
1273 reverse( {list}) List reverse {list} in-place | 1398 reverse( {list}) List reverse {list} in-place |
1274 search( {pattern} [, {flags}]) Number search for {pattern} | 1399 search( {pattern} [, {flags}]) Number search for {pattern} |
1903 filter({list}, {expr}) *filter()* *E712* | 2028 filter({list}, {expr}) *filter()* *E712* |
1904 For each item in {list} evaluate {expr} and when the result is | 2029 For each item in {list} evaluate {expr} and when the result is |
1905 zero remove the item from the List. | 2030 zero remove the item from the List. |
1906 Inside {expr} the symbol "&" stands for the existing | 2031 Inside {expr} the symbol "&" stands for the existing |
1907 item. Example: > | 2032 item. Example: > |
1908 :call filter(mylist, #& !~ "OLD"#) | 2033 :call filter(mylist, '& !~ "OLD"') |
1909 < Removes the items where "OLD" appears. | 2034 < Removes the items where "OLD" appears. And this: > |
2035 :call filter(mylist, 0) | |
2036 < Removes all the items, thus clears the List or Dictionary. | |
2037 | |
1910 Note that {expr} is an expression that evaluates to an | 2038 Note that {expr} is an expression that evaluates to an |
1911 expression. Often it is good to use a |sharp-string| to avoid | 2039 expression. Often it is good to use a |literal-string| to |
1912 having to double backslashes. | 2040 avoid having to double backslashes. |
1913 The operation is done in-place. If you want a list to remain | 2041 The operation is done in-place. If you want a list to remain |
1914 unmodified make a copy first: > | 2042 unmodified make a copy first: > |
1915 :let l = filter(copy(mylist), #& =~ "KEEP"#) | 2043 :let l = filter(copy(mylist), '& =~ "KEEP"') |
1916 < Returns {list}. | 2044 < Returns {list}. |
1917 | 2045 |
1918 | 2046 |
1919 finddir({name}[, {path}[, {count}]]) *finddir()* | 2047 finddir({name}[, {path}[, {count}]]) *finddir()* |
1920 Find directory {name} in {path}. | 2048 Find directory {name} in {path}. |
2522 let lines = join(mylist, "\n") . "\n" | 2650 let lines = join(mylist, "\n") . "\n" |
2523 < String items are used as-is. Lists and Dictionaries are | 2651 < String items are used as-is. Lists and Dictionaries are |
2524 converted into a string like with |string()|. | 2652 converted into a string like with |string()|. |
2525 The opposite function is |split()|. | 2653 The opposite function is |split()|. |
2526 | 2654 |
2655 keys({dict}) *keys()* | |
2656 Return a List with all the keys of {dict}. The List is in | |
2657 arbitrary order. | |
2658 | |
2527 *len()* *E701* | 2659 *len()* *E701* |
2528 len({expr}) The result is a Number, which is the length of the argument. | 2660 len({expr}) The result is a Number, which is the length of the argument. |
2529 When {expr} is a String or a Number the length in bytes is | 2661 When {expr} is a String or a Number the length in bytes is |
2530 used, as with |strlen()|. | 2662 used, as with |strlen()|. |
2531 When {expr} is a List the number of items in the List is | 2663 When {expr} is a List the number of items in the List is |
2635 map({list}, {expr}) *map()* | 2767 map({list}, {expr}) *map()* |
2636 Replace each item in {list} with the result of evaluating | 2768 Replace each item in {list} with the result of evaluating |
2637 {expr}. | 2769 {expr}. |
2638 Inside {expr} the symbol "&" stands for the existing | 2770 Inside {expr} the symbol "&" stands for the existing |
2639 item. Example: > | 2771 item. Example: > |
2640 :call map(mylist, #"> " . & . " <"#) | 2772 :call map(mylist, '"> " . & . " <"') |
2641 < This puts "> " before and " <" after each item in "mylist". | 2773 < This puts "> " before and " <" after each item in "mylist". |
2642 Note that {expr} is an expression that evaluates to an | 2774 Note that {expr} is an expression that evaluates to an |
2643 expression. Often it is good to use a |sharp-string| to avoid | 2775 expression. Often it is good to use a |literal-string| to |
2644 having to double backslashes. | 2776 avoid having to double backslashes. |
2645 The operation is done in-place. If you want a list to remain | 2777 The operation is done in-place. If you want a list to remain |
2646 unmodified make a copy first: > | 2778 unmodified make a copy first: > |
2647 :let tlist = map(copy(mylist), # & . "\t"#) | 2779 :let tlist = map(copy(mylist), ' & . "\t"') |
2648 < Returns {list}. | 2780 < Returns {list}. |
2649 | 2781 |
2650 | 2782 |
2651 maparg({name}[, {mode}]) *maparg()* | 2783 maparg({name}[, {mode}]) *maparg()* |
2652 Return the rhs of mapping {name} in mode {mode}. When there | 2784 Return the rhs of mapping {name} in mode {mode}. When there |
2815 let ind = indent(prevnonblank(v:lnum - 1)) | 2947 let ind = indent(prevnonblank(v:lnum - 1)) |
2816 < When {lnum} is invalid or there is no non-blank line at or | 2948 < When {lnum} is invalid or there is no non-blank line at or |
2817 above it, zero is returned. | 2949 above it, zero is returned. |
2818 Also see |nextnonblank()|. | 2950 Also see |nextnonblank()|. |
2819 | 2951 |
2952 range({expr} [, {max} [, {stride}]]) *range()* | |
2953 Returns a List with Numbers: | |
2954 - If only {expr} is specified: [0, 1, ..., {expr} - 1] | |
2955 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] | |
2956 - If {stride} is specified: [{expr}, {expr} + {stride}, ..., | |
2957 {max}] (increasing {expr} with {stride} each time, not | |
2958 producing a value past {max}). | |
2959 Examples: > | |
2960 range(4) " [0, 1, 2, 3] | |
2961 range(2, 4) " [2, 3, 4] | |
2962 range(2, 9, 3) " [2, 5, 8] | |
2963 range(2, -2, -1) " [2, 1, 0, -1, -2] | |
2964 < | |
2820 *remote_expr()* *E449* | 2965 *remote_expr()* *E449* |
2821 remote_expr({server}, {string} [, {idvar}]) | 2966 remote_expr({server}, {string} [, {idvar}]) |
2822 Send the {string} to {server}. The string is sent as an | 2967 Send the {string} to {server}. The string is sent as an |
2823 expression and the result is returned after evaluation. | 2968 expression and the result is returned after evaluation. |
2824 If {idvar} is present, it is taken as the name of a | 2969 If {idvar} is present, it is taken as the name of a |
2900 points to an item before {idx} this is an error. | 3045 points to an item before {idx} this is an error. |
2901 See |list-index| for possible values of {idx} and {end}. | 3046 See |list-index| for possible values of {idx} and {end}. |
2902 Example: > | 3047 Example: > |
2903 :echo "last item: " . remove(mylist, -1) | 3048 :echo "last item: " . remove(mylist, -1) |
2904 :call remove(mylist, 0, 9) | 3049 :call remove(mylist, 0, 9) |
2905 < Use |delete()| to remove a file. | 3050 remove({dict}, {key}) |
3051 Remove the entry from {dict} with key {key}. Example: > | |
3052 :echo "removed " . remove(dict, "one") | |
3053 < If there is no {key} in {dict} this is an error. | |
3054 | |
3055 Use |delete()| to remove a file. | |
2906 | 3056 |
2907 rename({from}, {to}) *rename()* | 3057 rename({from}, {to}) *rename()* |
2908 Rename the file by the name {from} to the name {to}. This | 3058 Rename the file by the name {from} to the name {to}. This |
2909 should also work to move files across file systems. The | 3059 should also work to move files across file systems. The |
2910 result is a Number, which is 0 if the file was renamed | 3060 result is a Number, which is 0 if the file was renamed |
3086 setcmdpos({pos}) *setcmdpos()* | 3236 setcmdpos({pos}) *setcmdpos()* |
3087 Set the cursor position in the command line to byte position | 3237 Set the cursor position in the command line to byte position |
3088 {pos}. The first position is 1. | 3238 {pos}. The first position is 1. |
3089 Use |getcmdpos()| to obtain the current position. | 3239 Use |getcmdpos()| to obtain the current position. |
3090 Only works while editing the command line, thus you must use | 3240 Only works while editing the command line, thus you must use |
3091 |c_CTRL-\_e| or |c_CTRL-R_=|. The position is set after the | 3241 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For |
3092 command line is set to the expression. | 3242 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is |
3243 set after the command line is set to the expression. For | |
3244 |c_CTRL-R_=| it is set after evaluating the expression but | |
3245 before inserting the resulting text. | |
3093 When the number is too big the cursor is put at the end of the | 3246 When the number is too big the cursor is put at the end of the |
3094 line. A number smaller than one has undefined results. | 3247 line. A number smaller than one has undefined results. |
3095 Returns 0 when successful, 1 when not editing the command | 3248 Returns 0 when successful, 1 when not editing the command |
3096 line. | 3249 line. |
3097 | 3250 |
3227 *string()* | 3380 *string()* |
3228 string({expr}) Return {expr} converted to a String. If {expr} is a Number, | 3381 string({expr}) Return {expr} converted to a String. If {expr} is a Number, |
3229 String or a composition of them, then the result can be parsed | 3382 String or a composition of them, then the result can be parsed |
3230 back with |eval()|. | 3383 back with |eval()|. |
3231 {expr} type result ~ | 3384 {expr} type result ~ |
3232 String #string# | 3385 String 'string' |
3233 Number 123 | 3386 Number 123 |
3234 Funcref function(#name#) | 3387 Funcref function('name') |
3235 List [item, item] | 3388 List [item, item] |
3236 Note that in String values the # character is doubled. | 3389 Note that in String values the ' character is doubled. |
3237 | 3390 |
3238 *strlen()* | 3391 *strlen()* |
3239 strlen({expr}) The result is a Number, which is the length of the String | 3392 strlen({expr}) The result is a Number, which is the length of the String |
3240 {expr} in bytes. If you want to count the number of | 3393 {expr} in bytes. If you want to count the number of |
3241 multi-byte characters use something like this: > | 3394 multi-byte characters use something like this: > |
4108 :call FixLine(lnum) | 4261 :call FixLine(lnum) |
4109 :let lnum = lnum + 1 | 4262 :let lnum = lnum + 1 |
4110 :endwhile | 4263 :endwhile |
4111 < | 4264 < |
4112 NOTE: The ":append" and ":insert" commands don't work | 4265 NOTE: The ":append" and ":insert" commands don't work |
4113 properly inside a :while" and ":for" loop. | 4266 properly inside a ":while" and ":for" loop. |
4114 | 4267 |
4115 :for {var} in {list} *:for* *E690* | 4268 :for {var} in {list} *:for* *E690* |
4116 :endfo[r] *:endfo* *:endfor* | 4269 :endfo[r] *:endfo* *:endfor* |
4117 Repeat the commands between ":for" and ":endfor" for | 4270 Repeat the commands between ":for" and ":endfor" for |
4118 each item in {list}. variable {var} is set to the | 4271 each item in {list}. variable {var} is set to the |
4356 command: > | 4509 command: > |
4357 :execute "normal ixxx\<Esc>" | 4510 :execute "normal ixxx\<Esc>" |
4358 < This has an <Esc> character, see |expr-string|. | 4511 < This has an <Esc> character, see |expr-string|. |
4359 | 4512 |
4360 Note: The executed string may be any command-line, but | 4513 Note: The executed string may be any command-line, but |
4361 you cannot start or end a "while" or "if" command. | 4514 you cannot start or end a "while", "for" or "if" |
4362 Thus this is illegal: > | 4515 command. Thus this is illegal: > |
4363 :execute 'while i > 5' | 4516 :execute 'while i > 5' |
4364 :execute 'echo "test" | break' | 4517 :execute 'echo "test" | break' |
4365 < | 4518 < |
4366 It is allowed to have a "while" or "if" command | 4519 It is allowed to have a "while" or "if" command |
4367 completely in the executed string: > | 4520 completely in the executed string: > |