comparison runtime/doc/eval.txt @ 95:a2081e6febb8

updated for version 7.0037
author vimboss
date Tue, 11 Jan 2005 21:29:04 +0000
parents 9d4f762cc1d9
children 04f2e519ab18
comparison
equal deleted inserted replaced
94:0c2e08de4a75 95:a2081e6febb8
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 09 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 11
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
221 :let [var1, var2; rest] = mylist 221 :let [var1, var2; rest] = mylist
222 222
223 This works like: > 223 This works like: >
224 :let var1 = mylist[0] 224 :let var1 = mylist[0]
225 :let var2 = mylist[1] 225 :let var2 = mylist[1]
226 :let rest = mjlist[2:] 226 :let rest = mylist[2:]
227 227
228 Except that there is no error if there are only two items. "rest" will be an 228 Except that there is no error if there are only two items. "rest" will be an
229 empty list then. 229 empty list then.
230 230
231 231
246 :call add(list, "new") " append String item 246 :call add(list, "new") " append String item
247 :call add(list, [1, 2]) " append List as one new item 247 :call add(list, [1, 2]) " append List as one new item
248 :call extend(list, [1, 2]) " extend the list with two more items 248 :call extend(list, [1, 2]) " extend the list with two more items
249 :let i = remove(list, 3) " remove item 3 249 :let i = remove(list, 3) " remove item 3
250 :let l = remove(list, 3, -1) " remove items 3 to last item 250 :let l = remove(list, 3, -1) " remove items 3 to last item
251 :call filter(list, #& =~ 'x'#) " remove items with an 'x'
251 252
252 Changing the oder of items in a list: > 253 Changing the oder of items in a list: >
253 :call sort(list) " sort a list alphabetically 254 :call sort(list) " sort a list alphabetically
254 :call reverse(list) " reverse the order of items 255 :call reverse(list) " reverse the order of items
255 256
271 :endwhile 272 :endwhile
272 273
273 Note that all items in the list should be of the same type, otherwise this 274 Note that all items in the list should be of the same type, otherwise this
274 results in an error |E706|. To avoid this |:unlet| the variable at the end of 275 results in an error |E706|. To avoid this |:unlet| the variable at the end of
275 the loop. 276 the loop.
277
278 If all you want to do is modify each item in the list then the |map()|
279 function might be a simpler method than a for loop.
276 280
277 Just like the |:let| command, |:for| also accepts a list of variables. This 281 Just like the |:let| command, |:for| also accepts a list of variables. This
278 requires the argument to be a list of lists. > 282 requires the argument to be a list of lists. >
279 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]] 283 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]]
280 : call Doit(lnum, col) 284 : call Doit(lnum, col)
302 :let small = min(list) " minumum value in a list 306 :let small = min(list) " minumum value in a list
303 :let xs = count(list, 'x') " count nr of times 'x' appears in list 307 :let xs = count(list, 'x') " count nr of times 'x' appears in list
304 :let i = index(list, 'x') " index of first 'x' in list 308 :let i = index(list, 'x') " index of first 'x' in list
305 :let lines = getline(1, 10) " get ten text lines from buffer 309 :let lines = getline(1, 10) " get ten text lines from buffer
306 :call append('$', lines) " append text lines in buffer 310 :call append('$', lines) " append text lines in buffer
307 :let list = str2list("a b c") " create list from items in a string 311 :let list = split("a b c") " create list from items in a string
312 :let string = join(list, ', ') " create string from list items
308 :let s = string() " String representation of a list 313 :let s = string() " String representation of a list
314 :call map(list, #'>> ' . &#) " prepend ">> " to each item
309 315
310 316
311 1.4 More about variables ~ 317 1.4 More about variables ~
312 *more-variables* 318 *more-variables*
313 If you need to know the type of a variable or expression, use the |type()| 319 If you need to know the type of a variable or expression, use the |type()|
375 expr9[expr1 : expr2] substring of a String or sublist of a List 381 expr9[expr1 : expr2] substring of a String or sublist of a List
376 382
377 |expr9| number number constant 383 |expr9| number number constant
378 "string" string constant, backslash is special 384 "string" string constant, backslash is special
379 'string' string constant 385 'string' string constant
386 #string# string constant
380 [expr1, ...] List 387 [expr1, ...] List
381 &option option value 388 &option option value
382 (expr1) nested expression 389 (expr1) nested expression
383 variable internal variable 390 variable internal variable
384 va{ria}ble internal variable with curly braces 391 va{ria}ble internal variable with curly braces
674 'string' string constant *expr-'* 681 'string' string constant *expr-'*
675 682
676 Note that single quotes are used. 683 Note that single quotes are used.
677 684
678 This string is taken as it is. No backslashes are removed or have a special 685 This string is taken as it is. No backslashes are removed or have a special
679 meaning. A literal-string cannot contain a single quote. Use a normal, 686 meaning. A literal-string cannot contain a single quote. Use a double-quoted
680 double-quoted string for that. 687 string or sharp-string for that.
681 688
682 Single quoted strings are useful for patterns, so that backslashes do not need 689 Single quoted strings are useful for patterns, so that backslashes do not need
683 to be doubled. These two commands are equivalent: > 690 to be doubled. These two commands are equivalent: >
684 if a =~ "\\s*" 691 if a =~ "\\s*"
685 if a =~ '\s*' 692 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.
686 704
687 705
688 option *expr-option* *E112* *E113* 706 option *expr-option* *E112* *E113*
689 ------ 707 ------
690 &option option value, local value if possible 708 &option option value, local value if possible
1144 cindent( {lnum}) Number C indent for line {lnum} 1162 cindent( {lnum}) Number C indent for line {lnum}
1145 col( {expr}) Number column nr of cursor or mark 1163 col( {expr}) Number column nr of cursor or mark
1146 confirm( {msg} [, {choices} [, {default} [, {type}]]]) 1164 confirm( {msg} [, {choices} [, {default} [, {type}]]])
1147 Number number of choice picked by user 1165 Number number of choice picked by user
1148 copy( {expr}) any make a shallow copy of {expr} 1166 copy( {expr}) any make a shallow copy of {expr}
1149 count( {list}, {expr} [, {ic}]) Number count how many {expr} are in {list} 1167 count( {list}, {expr} [, {start} [, {ic}]])
1168 Number count how many {expr} are in {list}
1150 cscope_connection( [{num} , {dbpath} [, {prepend}]]) 1169 cscope_connection( [{num} , {dbpath} [, {prepend}]])
1151 Number checks existence of cscope connection 1170 Number checks existence of cscope connection
1152 cursor( {lnum}, {col}) Number position cursor at {lnum}, {col} 1171 cursor( {lnum}, {col}) Number position cursor at {lnum}, {col}
1153 deepcopy( {expr}) any make a full copy of {expr} 1172 deepcopy( {expr}) any make a full copy of {expr}
1154 delete( {fname}) Number delete file {fname} 1173 delete( {fname}) Number delete file {fname}
1155 did_filetype() Number TRUE if FileType autocommand event used 1174 did_filetype() Number TRUE if FileType autocommand event used
1156 diff_filler( {lnum}) Number diff filler lines about {lnum} 1175 diff_filler( {lnum}) Number diff filler lines about {lnum}
1157 diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col} 1176 diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col}
1158 empty( {expr}) Number TRUE if {expr} is empty 1177 empty( {expr}) Number TRUE if {expr} is empty
1159 escape( {string}, {chars}) String escape {chars} in {string} with '\' 1178 escape( {string}, {chars}) String escape {chars} in {string} with '\'
1179 eval( {string}) any evaluate {string} into its value
1160 eventhandler( ) Number TRUE if inside an event handler 1180 eventhandler( ) Number TRUE if inside an event handler
1161 executable( {expr}) Number 1 if executable {expr} exists 1181 executable( {expr}) Number 1 if executable {expr} exists
1162 exists( {expr}) Number TRUE if {expr} exists 1182 exists( {expr}) Number TRUE if {expr} exists
1163 expand( {expr}) String expand special keywords in {expr} 1183 expand( {expr}) String expand special keywords in {expr}
1164 filereadable( {file}) Number TRUE if {file} is a readable file 1184 filereadable( {file}) Number TRUE if {file} is a readable file
1185 filter( {list}, {expr}) List remove from {list} where {expr} is 0
1186 finddir( {name}[, {path}[, {count}]])
1187 String Find directory {name} in {path}
1165 findfile( {name}[, {path}[, {count}]]) 1188 findfile( {name}[, {path}[, {count}]])
1166 String Find fine {name} in {path} 1189 String Find file {name} in {path}
1167 filewritable( {file}) Number TRUE if {file} is a writable file 1190 filewritable( {file}) Number TRUE if {file} is a writable file
1168 fnamemodify( {fname}, {mods}) String modify file name 1191 fnamemodify( {fname}, {mods}) String modify file name
1169 foldclosed( {lnum}) Number first line of fold at {lnum} if closed 1192 foldclosed( {lnum}) Number first line of fold at {lnum} if closed
1170 foldclosedend( {lnum}) Number last line of fold at {lnum} if closed 1193 foldclosedend( {lnum}) Number last line of fold at {lnum} if closed
1171 foldlevel( {lnum}) Number fold level at {lnum} 1194 foldlevel( {lnum}) Number fold level at {lnum}
1201 hlexists( {name}) Number TRUE if highlight group {name} exists 1224 hlexists( {name}) Number TRUE if highlight group {name} exists
1202 hlID( {name}) Number syntax ID of highlight group {name} 1225 hlID( {name}) Number syntax ID of highlight group {name}
1203 hostname() String name of the machine Vim is running on 1226 hostname() String name of the machine Vim is running on
1204 iconv( {expr}, {from}, {to}) String convert encoding of {expr} 1227 iconv( {expr}, {from}, {to}) String convert encoding of {expr}
1205 indent( {lnum}) Number indent of line {lnum} 1228 indent( {lnum}) Number indent of line {lnum}
1206 index( {list}, {expr} [, {ic}]) Number index in {list} where {expr} appears 1229 index( {list}, {expr} [, {start} [, {ic}]])
1230 Number index in {list} where {expr} appears
1207 input( {prompt} [, {text}]) String get input from the user 1231 input( {prompt} [, {text}]) String get input from the user
1208 inputdialog( {p} [, {t} [, {c}]]) String like input() but in a GUI dialog 1232 inputdialog( {p} [, {t} [, {c}]]) String like input() but in a GUI dialog
1209 inputrestore() Number restore typeahead 1233 inputrestore() Number restore typeahead
1210 inputsave() Number save and clear typeahead 1234 inputsave() Number save and clear typeahead
1211 inputsecret( {prompt} [, {text}]) String like input() but hiding the text 1235 inputsecret( {prompt} [, {text}]) String like input() but hiding the text
1212 insert( {list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] 1236 insert( {list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}]
1213 isdirectory( {directory}) Number TRUE if {directory} is a directory 1237 isdirectory( {directory}) Number TRUE if {directory} is a directory
1238 join( {list} [, {sep}]) String join {list} items into one String
1214 len( {expr}) Number the length of {expr} 1239 len( {expr}) Number the length of {expr}
1215 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} 1240 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
1216 libcallnr( {lib}, {func}, {arg}) Number idem, but return a Number 1241 libcallnr( {lib}, {func}, {arg}) Number idem, but return a Number
1217 line( {expr}) Number line nr of cursor, last line or mark 1242 line( {expr}) Number line nr of cursor, last line or mark
1218 line2byte( {lnum}) Number byte count of line {lnum} 1243 line2byte( {lnum}) Number byte count of line {lnum}
1219 lispindent( {lnum}) Number Lisp indent for line {lnum} 1244 lispindent( {lnum}) Number Lisp indent for line {lnum}
1220 localtime() Number current time 1245 localtime() Number current time
1246 map( {list}, {expr}) List change each item in {list} to {expr}
1221 maparg( {name}[, {mode}]) String rhs of mapping {name} in mode {mode} 1247 maparg( {name}[, {mode}]) String rhs of mapping {name} in mode {mode}
1222 mapcheck( {name}[, {mode}]) String check for mappings matching {name} 1248 mapcheck( {name}[, {mode}]) String check for mappings matching {name}
1223 match( {expr}, {pat}[, {start}[, {count}]]) 1249 match( {expr}, {pat}[, {start}[, {count}]])
1224 Number position where {pat} matches in {expr} 1250 Number position where {pat} matches in {expr}
1225 matchend( {expr}, {pat}[, {start}[, {count}]]) 1251 matchend( {expr}, {pat}[, {start}[, {count}]])
1256 setline( {lnum}, {line}) Number set line {lnum} to {line} 1282 setline( {lnum}, {line}) Number set line {lnum} to {line}
1257 setreg( {n}, {v}[, {opt}]) Number set register to value and type 1283 setreg( {n}, {v}[, {opt}]) Number set register to value and type
1258 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} 1284 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
1259 simplify( {filename}) String simplify filename as much as possible 1285 simplify( {filename}) String simplify filename as much as possible
1260 sort( {list} [, {func}]) List sort {list}, using {func} to compare 1286 sort( {list} [, {func}]) List sort {list}, using {func} to compare
1261 str2list( {expr} [, {pat}]) List make List from {pat} separated {expr} 1287 split( {expr} [, {pat}]) List make List from {pat} separated {expr}
1262 strftime( {format}[, {time}]) String time in specified format 1288 strftime( {format}[, {time}]) String time in specified format
1263 stridx( {haystack}, {needle}) Number first index of {needle} in {haystack} 1289 stridx( {haystack}, {needle}) Number first index of {needle} in {haystack}
1264 string( {expr}) String {expr} converted to a String 1290 string( {expr}) String String representation of {expr} value
1265 strlen( {expr}) Number length of the String {expr} 1291 strlen( {expr}) Number length of the String {expr}
1266 strpart( {src}, {start}[, {len}]) 1292 strpart( {src}, {start}[, {len}])
1267 String {len} characters of {src} at {start} 1293 String {len} characters of {src} at {start}
1268 strridx( {haystack}, {needle}) Number last index of {needle} in {haystack} 1294 strridx( {haystack}, {needle}) Number last index of {needle} in {haystack}
1269 strtrans( {expr}) String translate string to make it printable 1295 strtrans( {expr}) String translate string to make it printable
1569 that the original List can be changed without changing the 1595 that the original List can be changed without changing the
1570 copy, and vise versa. But the items are identical, thus 1596 copy, and vise versa. But the items are identical, thus
1571 changing an item changes the contents of both Lists. Also see 1597 changing an item changes the contents of both Lists. Also see
1572 |deepcopy()|. 1598 |deepcopy()|.
1573 1599
1574 count({list}, {expr} [, {ic}]) *count()* 1600 count({list}, {expr} [, {start} [, {ic}]]) *count()*
1575 Return the number of times an item with value {expr} appears 1601 Return the number of times an item with value {expr} appears
1576 in List {list}. 1602 in List {list}.
1603 If {start} is given then don't count items with a lower index.
1577 When {ic} is given and it's non-zero then case is ignored. 1604 When {ic} is given and it's non-zero then case is ignored.
1578 1605
1579 1606
1580 *cscope_connection()* 1607 *cscope_connection()*
1581 cscope_connection([{num} , {dbpath} [, {prepend}]]) 1608 cscope_connection([{num} , {dbpath} [, {prepend}]])
1688 Escape the characters in {chars} that occur in {string} with a 1715 Escape the characters in {chars} that occur in {string} with a
1689 backslash. Example: > 1716 backslash. Example: >
1690 :echo escape('c:\program files\vim', ' \') 1717 :echo escape('c:\program files\vim', ' \')
1691 < results in: > 1718 < results in: >
1692 c:\\program\ files\\vim 1719 c:\\program\ files\\vim
1693 < 1720
1721 < *eval()*
1722 eval({string}) Evaluate {string} and return the result. Especially useful to
1723 turn the result of |string()| back into the original value.
1724 This works for Numbers, Strings and composites of them.
1725 Also works for Funcrefs that refer to existing functions.
1726
1694 eventhandler() *eventhandler()* 1727 eventhandler() *eventhandler()*
1695 Returns 1 when inside an event handler. That is that Vim got 1728 Returns 1 when inside an event handler. That is that Vim got
1696 interrupted while waiting for the user to type a character, 1729 interrupted while waiting for the user to type a character,
1697 e.g., when dropping a file on Vim. This means interactive 1730 e.g., when dropping a file on Vim. This means interactive
1698 commands cannot be used. Otherwise zero is returned. 1731 commands cannot be used. Otherwise zero is returned.
1843 1876
1844 extend({list1}, {list2} [, {idx}]) *extend()* 1877 extend({list1}, {list2} [, {idx}]) *extend()*
1845 Append {list2} to {list1}. 1878 Append {list2} to {list1}.
1846 If {idx} is given insert the items of {list2} before item 1879 If {idx} is given insert the items of {list2} before item
1847 {idx} in {list1}. When {idx} is zero insert before the first 1880 {idx} in {list1}. When {idx} is zero insert before the first
1848 item. When {idx} is equal to len({list1}) {list2} is 1881 item. When {idx} is equal to len({list1}) then {list2} is
1849 appended. 1882 appended.
1850 {list1} is changed when {list2} is not empty. 1883 {list1} is changed when {list2} is not empty.
1851 {list2} remains unchanged. 1884 {list2} remains unchanged.
1852 {list1} and {list2} must be Lists. 1885 {list1} and {list2} must be Lists.
1853 Returns {list1}. 1886 Returns {list1}.
1863 name {file} exists, and can be read. If {file} doesn't exist, 1896 name {file} exists, and can be read. If {file} doesn't exist,
1864 or is a directory, the result is FALSE. {file} is any 1897 or is a directory, the result is FALSE. {file} is any
1865 expression, which is used as a String. 1898 expression, which is used as a String.
1866 *file_readable()* 1899 *file_readable()*
1867 Obsolete name: file_readable(). 1900 Obsolete name: file_readable().
1901
1902
1903 filter({list}, {expr}) *filter()* *E712*
1904 For each item in {list} evaluate {expr} and when the result is
1905 zero remove the item from the List.
1906 Inside {expr} the symbol "&" stands for the existing
1907 item. Example: >
1908 :call filter(mylist, #& !~ "OLD"#)
1909 < Removes the items where "OLD" appears.
1910 Note that {expr} is an expression that evaluates to an
1911 expression. Often it is good to use a |sharp-string| to avoid
1912 having to double backslashes.
1913 The operation is done in-place. If you want a list to remain
1914 unmodified make a copy first: >
1915 :let l = filter(copy(mylist), #& =~ "KEEP"#)
1916 < Returns {list}.
1917
1868 1918
1869 finddir({name}[, {path}[, {count}]]) *finddir()* 1919 finddir({name}[, {path}[, {count}]]) *finddir()*
1870 Find directory {name} in {path}. 1920 Find directory {name} in {path}.
1871 If {path} is omitted or empty then 'path' is used. 1921 If {path} is omitted or empty then 'path' is used.
1872 If the optional {count} is given, find {count}'s occurrence of 1922 If the optional {count} is given, find {count}'s occurrence of
2034 |c_CTRL-R_=|. 2084 |c_CTRL-R_=|.
2035 Example: > 2085 Example: >
2036 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> 2086 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
2037 < Also see |getcmdpos()| and |setcmdpos()|. 2087 < Also see |getcmdpos()| and |setcmdpos()|.
2038 2088
2039 getcmdpos({pos}) *getcmdpos()* 2089 getcmdpos() *getcmdpos()*
2040 Return the position of the cursor in the command line as a 2090 Return the position of the cursor in the command line as a
2041 byte count. The first column is 1. 2091 byte count. The first column is 1.
2042 Only works when editing the command line, thus requires use of 2092 Only works when editing the command line, thus requires use of
2043 |c_CTRL-\_e| or |c_CTRL-R_=|. Returns 0 otherwise. 2093 |c_CTRL-\_e| or |c_CTRL-R_=|. Returns 0 otherwise.
2044 Also see |setcmdpos()| and |getcmdline()|. 2094 Also see |setcmdpos()| and |getcmdline()|.
2356 of 'tabstop' is relevant. {lnum} is used just like in 2406 of 'tabstop' is relevant. {lnum} is used just like in
2357 |getline()|. 2407 |getline()|.
2358 When {lnum} is invalid -1 is returned. 2408 When {lnum} is invalid -1 is returned.
2359 2409
2360 2410
2361 index({list}, {expr} [, {ic}]) *index()* 2411 index({list}, {expr} [, {start} [, {ic}]]) *index()*
2362 Return the lowest index in List {list} where the item has a 2412 Return the lowest index in List {list} where the item has a
2363 value equal to {expr}. 2413 value equal to {expr}.
2414 If {start} is given then skip items with a lower index.
2364 When {ic} is given and it is non-zero, ignore case. Otherwise 2415 When {ic} is given and it is non-zero, ignore case. Otherwise
2365 case must match. 2416 case must match.
2366 -1 is returned when {expr} is not found in {list}. 2417 -1 is returned when {expr} is not found in {list}.
2367 Example: > 2418 Example: >
2368 :let idx = index(words, "the") 2419 :let idx = index(words, "the")
2459 The result is a Number, which is non-zero when a directory 2510 The result is a Number, which is non-zero when a directory
2460 with the name {directory} exists. If {directory} doesn't 2511 with the name {directory} exists. If {directory} doesn't
2461 exist, or isn't a directory, the result is FALSE. {directory} 2512 exist, or isn't a directory, the result is FALSE. {directory}
2462 is any expression, which is used as a String. 2513 is any expression, which is used as a String.
2463 2514
2515
2516 join({list} [, {sep}]) *join()*
2517 Join the items in {list} together into one String.
2518 When {sep} is specified it is put in between the items. If
2519 {sep} is omitted a single space is used.
2520 Note that {sep} is not added at the end. You might want to
2521 add it there too: >
2522 let lines = join(mylist, "\n") . "\n"
2523 < String items are used as-is. Lists and Dictionaries are
2524 converted into a string like with |string()|.
2525 The opposite function is |split()|.
2526
2464 *len()* *E701* 2527 *len()* *E701*
2465 len({expr}) The result is a Number, which is the length of the argument. 2528 len({expr}) The result is a Number, which is the length of the argument.
2466 When {expr} is a String or a Number the length in bytes is 2529 When {expr} is a String or a Number the length in bytes is
2467 used, as with |strlen()|. 2530 used, as with |strlen()|.
2468 When {expr} is a List the number of items in the List is 2531 When {expr} is a List the number of items in the List is
2565 |+lispindent| feature, -1 is returned. 2628 |+lispindent| feature, -1 is returned.
2566 2629
2567 localtime() *localtime()* 2630 localtime() *localtime()*
2568 Return the current time, measured as seconds since 1st Jan 2631 Return the current time, measured as seconds since 1st Jan
2569 1970. See also |strftime()| and |getftime()|. 2632 1970. See also |strftime()| and |getftime()|.
2633
2634
2635 map({list}, {expr}) *map()*
2636 Replace each item in {list} with the result of evaluating
2637 {expr}.
2638 Inside {expr} the symbol "&" stands for the existing
2639 item. Example: >
2640 :call map(mylist, #"> " . & . " <"#)
2641 < This puts "> " before and " <" after each item in "mylist".
2642 Note that {expr} is an expression that evaluates to an
2643 expression. Often it is good to use a |sharp-string| to avoid
2644 having to double backslashes.
2645 The operation is done in-place. If you want a list to remain
2646 unmodified make a copy first: >
2647 :let tlist = map(copy(mylist), # & . "\t"#)
2648 < Returns {list}.
2649
2570 2650
2571 maparg({name}[, {mode}]) *maparg()* 2651 maparg({name}[, {mode}]) *maparg()*
2572 Return the rhs of mapping {name} in mode {mode}. When there 2652 Return the rhs of mapping {name} in mode {mode}. When there
2573 is no mapping for {name}, an empty String is returned. 2653 is no mapping for {name}, an empty String is returned.
2574 These characters can be used for {mode}: 2654 These characters can be used for {mode}:
2615 :endif 2695 :endif
2616 < This avoids adding the "_vv" mapping when there already is a 2696 < This avoids adding the "_vv" mapping when there already is a
2617 mapping for "_v" or for "_vvv". 2697 mapping for "_v" or for "_vvv".
2618 2698
2619 match({expr}, {pat}[, {start}[, {count}]]) *match()* 2699 match({expr}, {pat}[, {start}[, {count}]]) *match()*
2620 The result is a Number, which gives the index (byte offset) in 2700 When {expr} is a List then this returns the index of the first
2621 {expr} where {pat} matches. 2701 item where {pat} matches. Each item is used as a String,
2622 A match at the first character returns zero. 2702 Lists and Dictionaries are used as echoed.
2703 Otherwise, {expr} is used as a String. The result is a
2704 Number, which gives the index (byte offset) in {expr} where
2705 {pat} matches.
2706 A match at the first character or List item returns zero.
2623 If there is no match -1 is returned. 2707 If there is no match -1 is returned.
2624 Example: > 2708 Example: >
2625 :echo match("testing", "ing") 2709 :echo match("testing", "ing") " results in 4
2626 < results in "4". 2710 :echo match([1, 'x'], '\a') " results in 2
2627 See |string-match| for how {pat} is used. 2711 < See |string-match| for how {pat} is used.
2712
2628 When {count} is given use the {count}'th match. When a match 2713 When {count} is given use the {count}'th match. When a match
2629 is found the search for the next one starts on character 2714 is found in a String the search for the next one starts on
2630 further. Thus this example results in 1: > 2715 character further. Thus this example results in 1: >
2631 echo match("testing", "..", 0, 2) 2716 echo match("testing", "..", 0, 2)
2632 < If {start} is given, the search starts from index {start}. 2717 < In a List the search continues in the next item.
2718
2719 If {start} is given, the search starts from byte index
2720 {start} in a String or item {start} in a List.
2633 The result, however, is still the index counted from the 2721 The result, however, is still the index counted from the
2634 first character. Example: > 2722 first character/item. Example: >
2635 :echo match("testing", "ing", 2) 2723 :echo match("testing", "ing", 2)
2636 < result is again "4". > 2724 < result is again "4". >
2637 :echo match("testing", "ing", 4) 2725 :echo match("testing", "ing", 4)
2638 < result is again "4". > 2726 < result is again "4". >
2639 :echo match("testing", "t", 2) 2727 :echo match("testing", "t", 2)
2640 < result is "3". 2728 < result is "3".
2641 If {start} < 0, it will be set to 0. 2729 For a String, if {start} < 0, it will be set to 0. For a list
2642 If {start} > strlen({expr}) -1 is returned. 2730 the index is counted from the end.
2731 If {start} is out of range (> strlen({expr} for a String or
2732 > len({expr} for a List) -1 is returned.
2733
2643 See |pattern| for the patterns that are accepted. 2734 See |pattern| for the patterns that are accepted.
2644 The 'ignorecase' option is used to set the ignore-caseness of 2735 The 'ignorecase' option is used to set the ignore-caseness of
2645 the pattern. 'smartcase' is NOT used. The matching is always 2736 the pattern. 'smartcase' is NOT used. The matching is always
2646 done like 'magic' is set and 'cpoptions' is empty. 2737 done like 'magic' is set and 'cpoptions' is empty.
2647 2738
2653 The {start}, if given, has the same meaning as for match(). > 2744 The {start}, if given, has the same meaning as for match(). >
2654 :echo matchend("testing", "ing", 2) 2745 :echo matchend("testing", "ing", 2)
2655 < results in "7". > 2746 < results in "7". >
2656 :echo matchend("testing", "ing", 5) 2747 :echo matchend("testing", "ing", 5)
2657 < result is "-1". 2748 < result is "-1".
2749 When {expr} is a List the result is equal to match().
2658 2750
2659 matchstr({expr}, {pat}[, {start}[, {count}]]) *matchstr()* 2751 matchstr({expr}, {pat}[, {start}[, {count}]]) *matchstr()*
2660 Same as match(), but return the matched string. Example: > 2752 Same as match(), but return the matched string. Example: >
2661 :echo matchstr("testing", "ing") 2753 :echo matchstr("testing", "ing")
2662 < results in "ing". 2754 < results in "ing".
2664 The {start}, if given, has the same meaning as for match(). > 2756 The {start}, if given, has the same meaning as for match(). >
2665 :echo matchstr("testing", "ing", 2) 2757 :echo matchstr("testing", "ing", 2)
2666 < results in "ing". > 2758 < results in "ing". >
2667 :echo matchstr("testing", "ing", 5) 2759 :echo matchstr("testing", "ing", 5)
2668 < result is "". 2760 < result is "".
2761 When {expr} is a List then the matching item is returned.
2762 The type isn't changed, it's not necessarily a String.
2669 2763
2670 *max()* 2764 *max()*
2671 max({list}) Return the maximum value of all items in {list}. 2765 max({list}) Return the maximum value of all items in {list}.
2672 If {list} is not a list or one of the items in {list} cannot 2766 If {list} is not a list or one of the items in {list} cannot
2673 be used as a Number this results in an error. 2767 be used as a Number this results in an error.
3074 sort({list} [, {func}]) *sort()* *E702* 3168 sort({list} [, {func}]) *sort()* *E702*
3075 Sort the items in {list} in-place. Returns {list}. If you 3169 Sort the items in {list} in-place. Returns {list}. If you
3076 want a list to remain unmodified make a copy first: > 3170 want a list to remain unmodified make a copy first: >
3077 :let sortedlist = sort(copy(mylist)) 3171 :let sortedlist = sort(copy(mylist))
3078 < Uses the string representation of each item to sort on. 3172 < Uses the string representation of each item to sort on.
3173 Numbers sort after Strings, Lists after Numbers.
3079 When {func} is given and it is one then case is ignored. 3174 When {func} is given and it is one then case is ignored.
3080 When {func} is a Funcref or a function name, this function is 3175 When {func} is a Funcref or a function name, this function is
3081 called to compare items. The function is invoked with two 3176 called to compare items. The function is invoked with two
3082 items as argument and must return zero if they are equal, 1 if 3177 items as argument and must return zero if they are equal, 1 if
3083 the first one sorts after the second one, -1 if the first one 3178 the first one sorts after the second one, -1 if the first one
3085 func MyCompare(i1, i2) 3180 func MyCompare(i1, i2)
3086 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 3181 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
3087 endfunc 3182 endfunc
3088 let sortedlist = sort(mylist, "MyCompare") 3183 let sortedlist = sort(mylist, "MyCompare")
3089 3184
3090 str2list({expr} [, {pattern}]) *str2list()* 3185 split({expr} [, {pattern}]) *split()*
3091 Make a List out of {expr}. When {pattern} is omitted each 3186 Make a List out of {expr}. When {pattern} is omitted each
3092 white-separated sequence of characters becomes an item. 3187 white-separated sequence of characters becomes an item.
3093 Otherwise the string is split where {pattern} matches, 3188 Otherwise the string is split where {pattern} matches,
3094 removing the matched characters. Empty strings are omitted. 3189 removing the matched characters. Empty strings are omitted.
3095 Example: > 3190 Example: >
3096 :let words = str2list(getline('.'), '\W\+') 3191 :let words = split(getline('.'), '\W\+')
3097 < Since empty strings are not added the "\+" isn't required but 3192 < Since empty strings are not added the "\+" isn't required but
3098 it makes the function work a bit faster. 3193 it makes the function work a bit faster.
3194 The opposite function is |join()|.
3099 3195
3100 3196
3101 strftime({format} [, {time}]) *strftime()* 3197 strftime({format} [, {time}]) *strftime()*
3102 The result is a String, which is a formatted date and time, as 3198 The result is a String, which is a formatted date and time, as
3103 specified by the {format} string. The given {time} is used, 3199 specified by the {format} string. The given {time} is used,
3127 :echo stridx("An Example", "Example") 3 3223 :echo stridx("An Example", "Example") 3
3128 :echo stridx("Starting point", "Start") 0 3224 :echo stridx("Starting point", "Start") 0
3129 :echo stridx("Starting point", "start") -1 3225 :echo stridx("Starting point", "start") -1
3130 < 3226 <
3131 *string()* 3227 *string()*
3132 string({expr}) Return {expr} converted to a String. 3228 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
3230 back with |eval()|.
3133 {expr} type result ~ 3231 {expr} type result ~
3134 String identical 3232 String #string#
3135 Number decimal representation 3233 Number 123
3136 Funcref name of the function 3234 Funcref function(#name#)
3137 List "[item, item]" form 3235 List [item, item]
3138 Note that string values are not in quotes, thus the result 3236 Note that in String values the # character is doubled.
3139 can't be parsed back to a List.
3140 3237
3141 *strlen()* 3238 *strlen()*
3142 strlen({expr}) The result is a Number, which is the length of the String 3239 strlen({expr}) The result is a Number, which is the length of the String
3143 {expr} in bytes. If you want to count the number of 3240 {expr} in bytes. If you want to count the number of
3144 multi-byte characters use something like this: > 3241 multi-byte characters use something like this: >