comparison runtime/doc/eval.txt @ 79:e918d3e340a4

updated for version 7.0032
author vimboss
date Thu, 06 Jan 2005 23:24:37 +0000
parents 388f285bda1b
children 366d9947baf2
comparison
equal deleted inserted replaced
78:b00be47310ed 79:e918d3e340a4
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 05 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 06
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
167 expr5 ==? expr5 equal, ignoring case 167 expr5 ==? expr5 equal, ignoring case
168 expr5 ==# expr5 equal, match case 168 expr5 ==# expr5 equal, match case
169 etc. As above, append ? for ignoring case, # for 169 etc. As above, append ? for ignoring case, # for
170 matching case 170 matching case
171 171
172 |expr5| expr6 + expr6 .. number addition 172 expr5 is expr5 same List instance
173 expr5 isnot expr5 different List instance
174
175 |expr5| expr6 + expr6 .. number addition or list concatenation
173 expr6 - expr6 .. number subtraction 176 expr6 - expr6 .. number subtraction
174 expr6 . expr6 .. string concatenation 177 expr6 . expr6 .. string concatenation
175 178
176 |expr6| expr7 * expr7 .. number multiplication 179 |expr6| expr7 * expr7 .. number multiplication
177 expr7 / expr7 .. number division 180 expr7 / expr7 .. number division
280 *expr-<* *expr-<=* *expr-=~* *expr-!~* 283 *expr-<* *expr-<=* *expr-=~* *expr-!~*
281 *expr-==#* *expr-!=#* *expr->#* *expr->=#* 284 *expr-==#* *expr-!=#* *expr->#* *expr->=#*
282 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#* 285 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#*
283 *expr-==?* *expr-!=?* *expr->?* *expr->=?* 286 *expr-==?* *expr-!=?* *expr->?* *expr->=?*
284 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?* 287 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?*
288 *expr-is*
285 use 'ignorecase' match case ignore case ~ 289 use 'ignorecase' match case ignore case ~
286 equal == ==# ==? 290 equal == ==# ==?
287 not equal != !=# !=? 291 not equal != !=# !=?
288 greater than > ># >? 292 greater than > ># >?
289 greater than or equal >= >=# >=? 293 greater than or equal >= >=# >=?
290 smaller than < <# <? 294 smaller than < <# <?
291 smaller than or equal <= <=# <=? 295 smaller than or equal <= <=# <=?
292 regexp matches =~ =~# =~? 296 regexp matches =~ =~# =~?
293 regexp doesn't match !~ !~# !~? 297 regexp doesn't match !~ !~# !~?
298 same instance is
299 different instance isnot
294 300
295 Examples: 301 Examples:
296 "abc" ==# "Abc" evaluates to 0 302 "abc" ==# "Abc" evaluates to 0
297 "abc" ==? "Abc" evaluates to 1 303 "abc" ==? "Abc" evaluates to 1
298 "abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise 304 "abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise
305
306 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
308 case means case is ignored when comparing item values.
309
310 A Funcref can only be compared with a Funcref and only "equal" and "not equal"
311 can be used. Case is never ignored.
312
313 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
315 original List. When using "is" without a List it is equivalent to using
316 "equal", using "isnot" equivalent to using "not equal". Except that a
317 different type means the values are different. "4 == '4'" is true, "4 is '4'"
318 is false.
299 319
300 When comparing a String with a Number, the String is converted to a Number, 320 When comparing a String with a Number, the String is converted to a Number,
301 and the comparison is done on Numbers. This means that "0 == 'x'" is TRUE, 321 and the comparison is done on Numbers. This means that "0 == 'x'" is TRUE,
302 because 'x' converted to a Number is zero. 322 because 'x' converted to a Number is zero.
303 323
324 "foo\nbar" =~ "\\n" evaluates to 0 344 "foo\nbar" =~ "\\n" evaluates to 0
325 345
326 346
327 expr5 and expr6 *expr5* *expr6* 347 expr5 and expr6 *expr5* *expr6*
328 --------------- 348 ---------------
329 expr6 + expr6 .. number addition *expr-+* 349 expr6 + expr6 .. Number addition or List concatenation *expr-+*
330 expr6 - expr6 .. number subtraction *expr--* 350 expr6 - expr6 .. Number subtraction *expr--*
331 expr6 . expr6 .. string concatenation *expr-.* 351 expr6 . expr6 .. String concatenation *expr-.*
332 352
333 expr7 * expr7 .. number multiplication *expr-star* 353 For Lists only "+" is possible and then both expr6 must be a list. The result
334 expr7 / expr7 .. number division *expr-/* 354 is a new list with the two lists Concatenated.
335 expr7 % expr7 .. number modulo *expr-%* 355
356 expr7 * expr7 .. number multiplication *expr-star*
357 expr7 / expr7 .. number division *expr-/*
358 expr7 % expr7 .. number modulo *expr-%*
336 359
337 For all, except ".", Strings are converted to Numbers. 360 For all, except ".", Strings are converted to Numbers.
338 361
339 Note the difference between "+" and ".": 362 Note the difference between "+" and ".":
340 "123" + "456" = 579 363 "123" + "456" = 579
341 "123" . "456" = "123456" 364 "123" . "456" = "123456"
342 365
343 When the righthand side of '/' is zero, the result is 0x7fffffff. 366 When the righthand side of '/' is zero, the result is 0x7fffffff.
344 When the righthand side of '%' is zero, the result is 0. 367 When the righthand side of '%' is zero, the result is 0.
368
369 None of these work for Funcrefs.
345 370
346 371
347 expr7 *expr7* 372 expr7 *expr7*
348 ----- 373 -----
349 ! expr7 logical NOT *expr-!* 374 ! expr7 logical NOT *expr-!*
923 bufname( {expr}) String Name of the buffer {expr} 948 bufname( {expr}) String Name of the buffer {expr}
924 bufnr( {expr}) Number Number of the buffer {expr} 949 bufnr( {expr}) Number Number of the buffer {expr}
925 bufwinnr( {expr}) Number window number of buffer {expr} 950 bufwinnr( {expr}) Number window number of buffer {expr}
926 byte2line( {byte}) Number line number at byte count {byte} 951 byte2line( {byte}) Number line number at byte count {byte}
927 byteidx( {expr}, {nr}) Number byte index of {nr}'th char in {expr} 952 byteidx( {expr}, {nr}) Number byte index of {nr}'th char in {expr}
953 call( {func}, {arglist}) any call {func} with arguments {arglist}
928 char2nr( {expr}) Number ASCII value of first char in {expr} 954 char2nr( {expr}) Number ASCII value of first char in {expr}
929 cindent( {lnum}) Number C indent for line {lnum} 955 cindent( {lnum}) Number C indent for line {lnum}
930 col( {expr}) Number column nr of cursor or mark 956 col( {expr}) Number column nr of cursor or mark
931 confirm( {msg} [, {choices} [, {default} [, {type}]]]) 957 confirm( {msg} [, {choices} [, {default} [, {type}]]])
932 Number number of choice picked by user 958 Number number of choice picked by user
933 copy( {expr}) any make a shallow copy of {expr} 959 copy( {expr}) any make a shallow copy of {expr}
960 count( {list}, {expr} [, {ic}]) Number count how many {expr} are in {list}
934 cscope_connection( [{num} , {dbpath} [, {prepend}]]) 961 cscope_connection( [{num} , {dbpath} [, {prepend}]])
935 Number checks existence of cscope connection 962 Number checks existence of cscope connection
936 cursor( {lnum}, {col}) Number position cursor at {lnum}, {col} 963 cursor( {lnum}, {col}) Number position cursor at {lnum}, {col}
937 deepcopy( {expr}) any make a full copy of {expr} 964 deepcopy( {expr}) any make a full copy of {expr}
938 delete( {fname}) Number delete file {fname} 965 delete( {fname}) Number delete file {fname}
983 hlexists( {name}) Number TRUE if highlight group {name} exists 1010 hlexists( {name}) Number TRUE if highlight group {name} exists
984 hlID( {name}) Number syntax ID of highlight group {name} 1011 hlID( {name}) Number syntax ID of highlight group {name}
985 hostname() String name of the machine Vim is running on 1012 hostname() String name of the machine Vim is running on
986 iconv( {expr}, {from}, {to}) String convert encoding of {expr} 1013 iconv( {expr}, {from}, {to}) String convert encoding of {expr}
987 indent( {lnum}) Number indent of line {lnum} 1014 indent( {lnum}) Number indent of line {lnum}
1015 index( {list}, {expr} [, {ic}]) Number index in {list} where {expr} appears
988 input( {prompt} [, {text}]) String get input from the user 1016 input( {prompt} [, {text}]) String get input from the user
989 inputdialog( {p} [, {t} [, {c}]]) String like input() but in a GUI dialog 1017 inputdialog( {p} [, {t} [, {c}]]) String like input() but in a GUI dialog
990 inputrestore() Number restore typeahead 1018 inputrestore() Number restore typeahead
991 inputsave() Number save and clear typeahead 1019 inputsave() Number save and clear typeahead
992 inputsecret( {prompt} [, {text}]) String like input() but hiding the text 1020 inputsecret( {prompt} [, {text}]) String like input() but hiding the text
1017 remote_peek( {serverid} [, {retvar}]) 1045 remote_peek( {serverid} [, {retvar}])
1018 Number check for reply string 1046 Number check for reply string
1019 remote_read( {serverid}) String read reply string 1047 remote_read( {serverid}) String read reply string
1020 remote_send( {server}, {string} [, {idvar}]) 1048 remote_send( {server}, {string} [, {idvar}])
1021 String send key sequence 1049 String send key sequence
1022 remove( {list}, {idx}) any remove item {idx} from {list} 1050 remove( {list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
1023 rename( {from}, {to}) Number rename (move) file from {from} to {to} 1051 rename( {from}, {to}) Number rename (move) file from {from} to {to}
1024 repeat( {expr}, {count}) String repeat {expr} {count} times 1052 repeat( {expr}, {count}) String repeat {expr} {count} times
1025 resolve( {filename}) String get filename a shortcut points to 1053 resolve( {filename}) String get filename a shortcut points to
1026 search( {pattern} [, {flags}]) Number search for {pattern} 1054 search( {pattern} [, {flags}]) Number search for {pattern}
1027 searchpair( {start}, {middle}, {end} [, {flags} [, {skip}]]) 1055 searchpair( {start}, {middle}, {end} [, {flags} [, {skip}]])
1233 echo strpart(s, 0, byteidx(s, 1)) 1261 echo strpart(s, 0, byteidx(s, 1))
1234 < If there are less than {nr} characters -1 is returned. 1262 < If there are less than {nr} characters -1 is returned.
1235 If there are exactly {nr} characters the length of the string 1263 If there are exactly {nr} characters the length of the string
1236 is returned. 1264 is returned.
1237 1265
1266 call({func}, {arglist}) *call()*
1267 Call function {func} with the items in List {arglist} as
1268 arguments.
1269 {func} can either be a Funcref or the name of a function.
1270 a:firstline and a:lastline are set to the cursor line.
1271 Returns the return value of the called function.
1272
1238 char2nr({expr}) *char2nr()* 1273 char2nr({expr}) *char2nr()*
1239 Return number value of the first char in {expr}. Examples: > 1274 Return number value of the first char in {expr}. Examples: >
1240 char2nr(" ") returns 32 1275 char2nr(" ") returns 32
1241 char2nr("ABC") returns 65 1276 char2nr("ABC") returns 65
1242 < The current 'encoding' is used. Example for "utf-8": > 1277 < The current 'encoding' is used. Example for "utf-8": >
1331 that the original List can be changed without changing the 1366 that the original List can be changed without changing the
1332 copy, and vise versa. But the items are identical, thus 1367 copy, and vise versa. But the items are identical, thus
1333 changing an item changes the contents of both Lists. Also see 1368 changing an item changes the contents of both Lists. Also see
1334 |deepcopy()|. 1369 |deepcopy()|.
1335 1370
1371 count({list}, {expr} [, {ic}]) *count()*
1372 Return the number of times an item with value {expr} appears
1373 in List {list}.
1374 When {ic} is given and it's non-zero then case is ignored.
1375
1376
1336 *cscope_connection()* 1377 *cscope_connection()*
1337 cscope_connection([{num} , {dbpath} [, {prepend}]]) 1378 cscope_connection([{num} , {dbpath} [, {prepend}]])
1338 Checks for the existence of a |cscope| connection. If no 1379 Checks for the existence of a |cscope| connection. If no
1339 parameters are specified, then the function returns: 1380 parameters are specified, then the function returns:
1340 0, if cscope was not available (not compiled in), or 1381 0, if cscope was not available (not compiled in), or
1587 left unchanged. Thus ":echo expand('$FOOBAR')" results in 1628 left unchanged. Thus ":echo expand('$FOOBAR')" results in
1588 "$FOOBAR". 1629 "$FOOBAR".
1589 1630
1590 See |glob()| for finding existing files. See |system()| for 1631 See |glob()| for finding existing files. See |system()| for
1591 getting the raw output of an external command. 1632 getting the raw output of an external command.
1633
1634 extend({list1}, {list2} [, {idx}]) *extend()*
1635 Append {list2} to {list1}.
1636 If {idx} is given insert the items of {list2} before item
1637 {idx} in {list1}. When {idx} is zero insert before the first
1638 item. When {idx} is equal to len({list1}) {list2} is
1639 appended.
1640 {list1} is changed when {list2} is not empty.
1641 {list2} remains unchanged.
1642 {list1} and {list2} must be Lists.
1643 Returns {list1}.
1644 Examples: >
1645 :echo sort(extend(mylist, [7, 5]))
1646 :call extend(mylist, [2, 3], 1)
1647 < Use |append()| to concatenate one item to a list. To
1648 concatenate two lists into a new list use the + operator: >
1649 :let newlist = [1, 2, 3] + [4, 5]
1592 1650
1593 filereadable({file}) *filereadable()* 1651 filereadable({file}) *filereadable()*
1594 The result is a Number, which is TRUE when a file with the 1652 The result is a Number, which is TRUE when a file with the
1595 name {file} exists, and can be read. If {file} doesn't exist, 1653 name {file} exists, and can be read. If {file} doesn't exist,
1596 or is a directory, the result is FALSE. {file} is any 1654 or is a directory, the result is FALSE. {file} is any
2065 current buffer. The indent is counted in spaces, the value 2123 current buffer. The indent is counted in spaces, the value
2066 of 'tabstop' is relevant. {lnum} is used just like in 2124 of 'tabstop' is relevant. {lnum} is used just like in
2067 |getline()|. 2125 |getline()|.
2068 When {lnum} is invalid -1 is returned. 2126 When {lnum} is invalid -1 is returned.
2069 2127
2128
2129 index({list}, {expr} [, {ic}]) *index()*
2130 Return the lowest index in List {list} where the item has a
2131 value equal to {expr}.
2132 When {ic} is given and it is non-zero, ignore case. Otherwise
2133 case must match.
2134 -1 is returned when {expr} is not found in {list}.
2135 Example: >
2136 :let idx = index(words, "the")
2137
2138
2070 input({prompt} [, {text}]) *input()* 2139 input({prompt} [, {text}]) *input()*
2071 The result is a String, which is whatever the user typed on 2140 The result is a String, which is whatever the user typed on
2072 the command-line. The parameter is either a prompt string, or 2141 the command-line. The parameter is either a prompt string, or
2073 a blank string (for no prompt). A '\n' can be used in the 2142 a blank string (for no prompt). A '\n' can be used in the
2074 prompt to start a new line. The highlighting set with 2143 prompt to start a new line. The highlighting set with
2482 \ echo remote_read(expand("<amatch>")) 2551 \ echo remote_read(expand("<amatch>"))
2483 :echo remote_send("gvim", ":sleep 10 | echo ". 2552 :echo remote_send("gvim", ":sleep 10 | echo ".
2484 \ 'server2client(expand("<client>"), "HELLO")<CR>') 2553 \ 'server2client(expand("<client>"), "HELLO")<CR>')
2485 2554
2486 2555
2487 remove({list}, {idx}) *remove()* 2556 remove({list}, {idx} [, {end}]) *remove()*
2488 Remove the item at {idx} from List {list} and return it. 2557 Without {end}: Remove the item at {idx} from List {list} and
2489 See |list-index| for possible values of {idx}. 2558 return it.
2559 With {end}: Remove items from {idx} to {end} (inclusive) and
2560 return a list with these items. When {idx} points to the same
2561 item as {end} a list with one item is returned. When {end}
2562 points to an item before {idx} this is an error.
2563 See |list-index| for possible values of {idx} and {end}.
2490 Example: > 2564 Example: >
2491 :echo "last item: " . remove(mylist, -1) 2565 :echo "last item: " . remove(mylist, -1)
2566 :call remove(mylist, 0, 9)
2492 < Use |delete()| to remove a file. 2567 < Use |delete()| to remove a file.
2493 2568
2494 rename({from}, {to}) *rename()* 2569 rename({from}, {to}) *rename()*
2495 Rename the file by the name {from} to the name {to}. This 2570 Rename the file by the name {from} to the name {to}. This
2496 should also work to move files across file systems. The 2571 should also work to move files across file systems. The
2501 repeat({expr}, {count}) *repeat()* 2576 repeat({expr}, {count}) *repeat()*
2502 Repeat {expr} {count} times and return the concatenated 2577 Repeat {expr} {count} times and return the concatenated
2503 result. Example: > 2578 result. Example: >
2504 :let seperator = repeat('-', 80) 2579 :let seperator = repeat('-', 80)
2505 < When {count} is zero or negative the result is empty. 2580 < When {count} is zero or negative the result is empty.
2581 When {expr} is a list the result is {expr} concatenated
2582 {count} times. Example: >
2583 :let longlist = repeat(['a', 'b'], 3)
2584 < Results in ['a', 'b', 'a', 'b', 'a', 'b'].
2506 2585
2507 resolve({filename}) *resolve()* *E655* 2586 resolve({filename}) *resolve()* *E655*
2508 On MS-Windows, when {filename} is a shortcut (a .lnk file), 2587 On MS-Windows, when {filename} is a shortcut (a .lnk file),
2509 returns the path the shortcut points to in a simplified form. 2588 returns the path the shortcut points to in a simplified form.
2510 On Unix, repeat resolving symbolic links in all path 2589 On Unix, repeat resolving symbolic links in all path
3631 properly inside a :while" and ":for" loop. 3710 properly inside a :while" and ":for" loop.
3632 3711
3633 :for {var} in {list} *:for* 3712 :for {var} in {list} *:for*
3634 :endfo[r] *:endfo* *:endfor* 3713 :endfo[r] *:endfo* *:endfor*
3635 Repeat the commands between ":for" and ":endfor" for 3714 Repeat the commands between ":for" and ":endfor" for
3636 each item in {list}. {var} is set to the value of the 3715 each item in {list}. variable {var} is set to the
3637 item. 3716 value of each item.
3638 When an error is detected from a command inside the 3717 When an error is detected for a command inside the
3639 loop, execution continues after the "endfor". 3718 loop, execution continues after the "endfor".
3640 A copy of {list} is made, so that it cannot change 3719 Changing {list} affects what items are used. Make a
3641 while executing the commands. Example (an inefficient 3720 copy if this is unwanted: >
3642 way to make a list empty): > 3721 :for item in copy(mylist)
3643 :for a in mylist 3722 < When not making a copy, Vim stores a reference to the
3723 next item in the list, before executing the commands
3724 with the current item. Thus the current item can be
3725 removed without effect. Removing any later item means
3726 it will not be found. Thus the following example
3727 works (an inefficient way to make a list empty): >
3728 :for item in mylist
3644 :call remove(mylist, 0) 3729 :call remove(mylist, 0)
3645 :endfor 3730 :endfor
3646 < Note that the type of each list item should be 3731 < Note that the type of each list item should be
3647 identical to avoid errors for the type of {var} 3732 identical to avoid errors for the type of {var}
3648 changing. Unlet the variable at the end of the loop 3733 changing. Unlet the variable at the end of the loop