Mercurial > vim
comparison runtime/doc/eval.txt @ 282:33d9c918b8ab
updated for version 7.0075
author | vimboss |
---|---|
date | Sun, 22 May 2005 22:07:59 +0000 |
parents | fe16c18c24a7 |
children | f811be6fa9b5 |
comparison
equal
deleted
inserted
replaced
281:cd05cd5cea91 | 282:33d9c918b8ab |
---|---|
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 May 18 | 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 May 22 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
1495 getftime( {fname}) Number last modification time of file | 1495 getftime( {fname}) Number last modification time of file |
1496 getftype( {fname}) String description of type of file {fname} | 1496 getftype( {fname}) String description of type of file {fname} |
1497 getline( {lnum}) String line {lnum} of current buffer | 1497 getline( {lnum}) String line {lnum} of current buffer |
1498 getline( {lnum}, {end}) List lines {lnum} to {end} of current buffer | 1498 getline( {lnum}, {end}) List lines {lnum} to {end} of current buffer |
1499 getqflist() List list of quickfix items | 1499 getqflist() List list of quickfix items |
1500 getreg( [{regname}]) String contents of register | 1500 getreg( [{regname} [, 1]]) String contents of register |
1501 getregtype( [{regname}]) String type of register | 1501 getregtype( [{regname}]) String type of register |
1502 getwinposx() Number X coord in pixels of GUI Vim window | 1502 getwinposx() Number X coord in pixels of GUI Vim window |
1503 getwinposy() Number Y coord in pixels of GUI Vim window | 1503 getwinposy() Number Y coord in pixels of GUI Vim window |
1504 getwinvar( {nr}, {varname}) variable {varname} in window {nr} | 1504 getwinvar( {nr}, {varname}) variable {varname} in window {nr} |
1505 glob( {expr}) String expand file wildcards in {expr} | 1505 glob( {expr}) String expand file wildcards in {expr} |
1585 setqflist( {list}[, {action}]) Number set list of quickfix items using {list} | 1585 setqflist( {list}[, {action}]) Number set list of quickfix items using {list} |
1586 setreg( {n}, {v}[, {opt}]) Number set register to value and type | 1586 setreg( {n}, {v}[, {opt}]) Number set register to value and type |
1587 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} | 1587 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} |
1588 simplify( {filename}) String simplify filename as much as possible | 1588 simplify( {filename}) String simplify filename as much as possible |
1589 sort( {list} [, {func}]) List sort {list}, using {func} to compare | 1589 sort( {list} [, {func}]) List sort {list}, using {func} to compare |
1590 split( {expr} [, {pat}]) List make List from {pat} separated {expr} | 1590 split( {expr} [, {pat} [, {keepempty}]]) |
1591 List make List from {pat} separated {expr} | |
1591 strftime( {format}[, {time}]) String time in specified format | 1592 strftime( {format}[, {time}]) String time in specified format |
1592 stridx( {haystack}, {needle}[, {start}]) | 1593 stridx( {haystack}, {needle}[, {start}]) |
1593 Number index of {needle} in {haystack} | 1594 Number index of {needle} in {haystack} |
1594 string( {expr}) String String representation of {expr} value | 1595 string( {expr}) String String representation of {expr} value |
1595 strlen( {expr}) Number length of the String {expr} | 1596 strlen( {expr}) Number length of the String {expr} |
2556 :for d in getqflist() | 2557 :for d in getqflist() |
2557 : echo bufname(d.bufnr) ':' d.lnum '=' d.text | 2558 : echo bufname(d.bufnr) ':' d.lnum '=' d.text |
2558 :endfor | 2559 :endfor |
2559 | 2560 |
2560 | 2561 |
2561 getreg([{regname}]) *getreg()* | 2562 getreg([{regname} [, 1]]) *getreg()* |
2562 The result is a String, which is the contents of register | 2563 The result is a String, which is the contents of register |
2563 {regname}. Example: > | 2564 {regname}. Example: > |
2564 :let cliptext = getreg('*') | 2565 :let cliptext = getreg('*') |
2565 < getreg('=') returns the last evaluated value of the expression | 2566 < getreg('=') returns the last evaluated value of the expression |
2566 register. (For use in maps.) | 2567 register. (For use in maps.) |
2568 getreg('=', 1) returns the expression itself, so that it can | |
2569 be restored with |setreg()|. For other registers the extra | |
2570 argument is ignored, thus you can always give it. | |
2567 If {regname} is not specified, |v:register| is used. | 2571 If {regname} is not specified, |v:register| is used. |
2568 | 2572 |
2569 | 2573 |
2570 getregtype([{regname}]) *getregtype()* | 2574 getregtype([{regname}]) *getregtype()* |
2571 The result is a String, which is type of register {regname}. | 2575 The result is a String, which is type of register {regname}. |
2574 "V" for |linewise| text | 2578 "V" for |linewise| text |
2575 "<CTRL-V>{width}" for |blockwise-visual| text | 2579 "<CTRL-V>{width}" for |blockwise-visual| text |
2576 0 for an empty or unknown register | 2580 0 for an empty or unknown register |
2577 <CTRL-V> is one character with value 0x16. | 2581 <CTRL-V> is one character with value 0x16. |
2578 If {regname} is not specified, |v:register| is used. | 2582 If {regname} is not specified, |v:register| is used. |
2579 | |
2580 | 2583 |
2581 *getwinposx()* | 2584 *getwinposx()* |
2582 getwinposx() The result is a Number, which is the X coordinate in pixels of | 2585 getwinposx() The result is a Number, which is the X coordinate in pixels of |
2583 the left hand side of the GUI Vim window. The result will be | 2586 the left hand side of the GUI Vim window. The result will be |
2584 -1 if the information is not available. | 2587 -1 if the information is not available. |
3596 line. | 3599 line. |
3597 | 3600 |
3598 setline({lnum}, {line}) *setline()* | 3601 setline({lnum}, {line}) *setline()* |
3599 Set line {lnum} of the current buffer to {line}. | 3602 Set line {lnum} of the current buffer to {line}. |
3600 {lnum} is used like with |getline()|. | 3603 {lnum} is used like with |getline()|. |
3604 When {lnum} is just below the last line the {line} will be | |
3605 added as a new line. | |
3601 If this succeeds, 0 is returned. If this fails (most likely | 3606 If this succeeds, 0 is returned. If this fails (most likely |
3602 because {lnum} is invalid) 1 is returned. Example: > | 3607 because {lnum} is invalid) 1 is returned. Example: > |
3603 :call setline(5, strftime("%c")) | 3608 :call setline(5, strftime("%c")) |
3609 < When {line} is a List then line {lnum} and following lines | |
3610 will be set to the items in the list. Example: > | |
3611 :call setline(5, ['aaa', 'bbb', 'ccc']) | |
3612 < This is equivalent to: > | |
3613 :for [n, l] in [[5, 6, 7], ['aaa', 'bbb', 'ccc']] | |
3614 : call setline(n, l) | |
3615 :endfor | |
3604 < Note: The '[ and '] marks are not set. | 3616 < Note: The '[ and '] marks are not set. |
3605 | 3617 |
3606 | 3618 |
3607 setqflist({list} [, {action}]) *setqflist()* | 3619 setqflist({list} [, {action}]) *setqflist()* |
3608 Creates a quickfix list using the items in {list}. Each item | 3620 Creates a quickfix list using the items in {list}. Each item |
3667 :call setreg('*', @%, 'ac') | 3679 :call setreg('*', @%, 'ac') |
3668 :call setreg('a', "1\n2\n3", 'b5') | 3680 :call setreg('a', "1\n2\n3", 'b5') |
3669 | 3681 |
3670 < This example shows using the functions to save and restore a | 3682 < This example shows using the functions to save and restore a |
3671 register. > | 3683 register. > |
3672 :let var_a = getreg('a') | 3684 :let var_a = getreg('a', 1) |
3673 :let var_amode = getregtype('a') | 3685 :let var_amode = getregtype('a') |
3674 .... | 3686 .... |
3675 :call setreg('a', var_a, var_amode) | 3687 :call setreg('a', var_a, var_amode) |
3676 | 3688 |
3677 < You can also change the type of a register by appending | 3689 < You can also change the type of a register by appending |
3710 Sort the items in {list} in-place. Returns {list}. If you | 3722 Sort the items in {list} in-place. Returns {list}. If you |
3711 want a list to remain unmodified make a copy first: > | 3723 want a list to remain unmodified make a copy first: > |
3712 :let sortedlist = sort(copy(mylist)) | 3724 :let sortedlist = sort(copy(mylist)) |
3713 < Uses the string representation of each item to sort on. | 3725 < Uses the string representation of each item to sort on. |
3714 Numbers sort after Strings, Lists after Numbers. | 3726 Numbers sort after Strings, Lists after Numbers. |
3727 For sorting text in the current buffer use |:sort|. | |
3715 When {func} is given and it is one then case is ignored. | 3728 When {func} is given and it is one then case is ignored. |
3716 When {func} is a Funcref or a function name, this function is | 3729 When {func} is a Funcref or a function name, this function is |
3717 called to compare items. The function is invoked with two | 3730 called to compare items. The function is invoked with two |
3718 items as argument and must return zero if they are equal, 1 if | 3731 items as argument and must return zero if they are equal, 1 if |
3719 the first one sorts after the second one, -1 if the first one | 3732 the first one sorts after the second one, -1 if the first one |
3721 func MyCompare(i1, i2) | 3734 func MyCompare(i1, i2) |
3722 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 | 3735 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 |
3723 endfunc | 3736 endfunc |
3724 let sortedlist = sort(mylist, "MyCompare") | 3737 let sortedlist = sort(mylist, "MyCompare") |
3725 | 3738 |
3726 split({expr} [, {pattern}]) *split()* | 3739 split({expr} [, {pattern} [, {keepempty}]]) *split()* |
3727 Make a List out of {expr}. When {pattern} is omitted each | 3740 Make a List out of {expr}. When {pattern} is omitted or empty |
3728 white-separated sequence of characters becomes an item. | 3741 each white-separated sequence of characters becomes an item. |
3729 Otherwise the string is split where {pattern} matches, | 3742 Otherwise the string is split where {pattern} matches, |
3730 removing the matched characters. Empty strings are omitted. | 3743 removing the matched characters. |
3744 When the first or last item is empty it is omitted, unless the | |
3745 {keepempty} argument is given and it's non-zero. | |
3731 Example: > | 3746 Example: > |
3732 :let words = split(getline('.'), '\W\+') | 3747 :let words = split(getline('.'), '\W\+') |
3733 < Since empty strings are not added the "\+" isn't required but | 3748 < To split a string in individual characters: > |
3734 it makes the function work a bit faster. | |
3735 To split a string in individual characters: > | |
3736 :for c in split(mystring, '\zs') | 3749 :for c in split(mystring, '\zs') |
3737 < If you want to keep the separator you can also use '\zs': > | 3750 < If you want to keep the separator you can also use '\zs': > |
3738 :echo split('abc:def:ghi', ':\zs') | 3751 :echo split('abc:def:ghi', ':\zs') |
3739 < ['abc:', 'def:', 'ghi'] ~ | 3752 < ['abc:', 'def:', 'ghi'] ~ |
3740 The opposite function is |join()|. | 3753 Splitting a table where the first element can be empty: > |
3754 :let items = split(line, ':', 1) | |
3755 < The opposite function is |join()|. | |
3741 | 3756 |
3742 | 3757 |
3743 strftime({format} [, {time}]) *strftime()* | 3758 strftime({format} [, {time}]) *strftime()* |
3744 The result is a String, which is a formatted date and time, as | 3759 The result is a String, which is a formatted date and time, as |
3745 specified by the {format} string. The given {time} is used, | 3760 specified by the {format} string. The given {time} is used, |