comparison runtime/doc/eval.txt @ 82:366d9947baf2

updated for version 7.0033
author vimboss
date Fri, 07 Jan 2005 21:48:26 +0000
parents e918d3e340a4
children fc244e0a6e7e
comparison
equal deleted inserted replaced
81:bf3f798c35c6 82:366d9947baf2
1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 06 1 *eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 07
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
932 932
933 (Use CTRL-] on the function name to jump to the full explanation) 933 (Use CTRL-] on the function name to jump to the full explanation)
934 934
935 USAGE RESULT DESCRIPTION ~ 935 USAGE RESULT DESCRIPTION ~
936 936
937 add( {list}, {item}) List append {item} to List {list}
937 append( {lnum}, {string}) Number append {string} below line {lnum} 938 append( {lnum}, {string}) Number append {string} below line {lnum}
938 append( {list}, {item}) List append {item} to List {list}
939 argc() Number number of files in the argument list 939 argc() Number number of files in the argument list
940 argidx() Number current index in the argument list 940 argidx() Number current index in the argument list
941 argv( {nr}) String {nr} entry of the argument list 941 argv( {nr}) String {nr} entry of the argument list
942 browse( {save}, {title}, {initdir}, {default}) 942 browse( {save}, {title}, {initdir}, {default})
943 String put up a file requester 943 String put up a file requester
980 foldclosedend( {lnum}) Number last line of fold at {lnum} if closed 980 foldclosedend( {lnum}) Number last line of fold at {lnum} if closed
981 foldlevel( {lnum}) Number fold level at {lnum} 981 foldlevel( {lnum}) Number fold level at {lnum}
982 foldtext( ) String line displayed for closed fold 982 foldtext( ) String line displayed for closed fold
983 foreground( ) Number bring the Vim window to the foreground 983 foreground( ) Number bring the Vim window to the foreground
984 function( {name}) Funcref reference to function {name} 984 function( {name}) Funcref reference to function {name}
985 get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
985 getchar( [expr]) Number get one character from the user 986 getchar( [expr]) Number get one character from the user
986 getcharmod( ) Number modifiers for the last typed character 987 getcharmod( ) Number modifiers for the last typed character
987 getbufvar( {expr}, {varname}) variable {varname} in buffer {expr} 988 getbufvar( {expr}, {varname}) variable {varname} in buffer {expr}
988 getcmdline() String return the current command-line 989 getcmdline() String return the current command-line
989 getcmdpos() Number return cursor position in command-line 990 getcmdpos() Number return cursor position in command-line
1049 String send key sequence 1050 String send key sequence
1050 remove( {list}, {idx} [, {end}]) any remove items {idx}-{end} from {list} 1051 remove( {list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
1051 rename( {from}, {to}) Number rename (move) file from {from} to {to} 1052 rename( {from}, {to}) Number rename (move) file from {from} to {to}
1052 repeat( {expr}, {count}) String repeat {expr} {count} times 1053 repeat( {expr}, {count}) String repeat {expr} {count} times
1053 resolve( {filename}) String get filename a shortcut points to 1054 resolve( {filename}) String get filename a shortcut points to
1055 reverse( {list}) List reverse {list} in-place
1054 search( {pattern} [, {flags}]) Number search for {pattern} 1056 search( {pattern} [, {flags}]) Number search for {pattern}
1055 searchpair( {start}, {middle}, {end} [, {flags} [, {skip}]]) 1057 searchpair( {start}, {middle}, {end} [, {flags} [, {skip}]])
1056 Number search for other end of start/end pair 1058 Number search for other end of start/end pair
1057 server2client( {clientid}, {string}) 1059 server2client( {clientid}, {string})
1058 Number send reply string 1060 Number send reply string
1061 setcmdpos( {pos}) Number set cursor position in command-line 1063 setcmdpos( {pos}) Number set cursor position in command-line
1062 setline( {lnum}, {line}) Number set line {lnum} to {line} 1064 setline( {lnum}, {line}) Number set line {lnum} to {line}
1063 setreg( {n}, {v}[, {opt}]) Number set register to value and type 1065 setreg( {n}, {v}[, {opt}]) Number set register to value and type
1064 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} 1066 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
1065 simplify( {filename}) String simplify filename as much as possible 1067 simplify( {filename}) String simplify filename as much as possible
1068 sort( {list} [, {func}]) List sort {list}, using {func} to compare
1069 str2list( {expr} [, {pat}]) List make List from {pat} separated {expr}
1066 strftime( {format}[, {time}]) String time in specified format 1070 strftime( {format}[, {time}]) String time in specified format
1067 stridx( {haystack}, {needle}) Number first index of {needle} in {haystack} 1071 stridx( {haystack}, {needle}) Number first index of {needle} in {haystack}
1068 string( {expr}) String {expr} converted to a String 1072 string( {expr}) String {expr} converted to a String
1069 strlen( {expr}) Number length of the String {expr} 1073 strlen( {expr}) Number length of the String {expr}
1070 strpart( {src}, {start}[, {len}]) 1074 strpart( {src}, {start}[, {len}])
1093 winline() Number window line of the cursor 1097 winline() Number window line of the cursor
1094 winnr() Number number of current window 1098 winnr() Number number of current window
1095 winrestcmd() String returns command to restore window sizes 1099 winrestcmd() String returns command to restore window sizes
1096 winwidth( {nr}) Number width of window {nr} 1100 winwidth( {nr}) Number width of window {nr}
1097 1101
1098 append({expr1}, {expr2}) *append()* 1102 add({list}, {expr}) *add()*
1099 If {expr1} is a List: Append the item {expr2} to List {expr1}. 1103 Append the item {expr} to List {list}. Returns the resulting
1100 Returns the resulting List. Examples: > 1104 List. Examples: >
1101 :let alist = append([1, 2, 3], item) 1105 :let alist = add([1, 2, 3], item)
1102 :call append(mylist, "woodstock") 1106 :call add(mylist, "woodstock")
1103 < Note that when {expr2} is a List it is appended as a single 1107 < Note that when {expr} is a List it is appended as a single
1104 item. Use |extend()| to concatenate Lists. 1108 item. Use |extend()| to concatenate Lists.
1105 1109
1106 When {expr1} is not a List: Append the text {expr2} after line 1110
1107 {expr1} in the current buffer. {expr1} can be zero, to insert 1111 append({lnum}, {expr}) *append()*
1108 a line before the first one. Returns 1 for failure ({expr1} 1112 When {expr} is a List: Append each item of the list as a text
1109 out of range or out of memory), 0 for success. Example: > 1113 line below line {lnum} in the current buffer.
1114 Otherwise append the text line {expr} below line {lnum} in the
1115 current buffer.
1116 {lnum} can be zero, to insert a line before the first one.
1117 Returns 1 for failure ({lnum} out of range or out of memory),
1118 0 for success. Example: >
1110 :let failed = append(line('$'), "# THE END") 1119 :let failed = append(line('$'), "# THE END")
1120 :let failed = append(0, ["Chapter 1", "the beginning"])
1111 < 1121 <
1112 *argc()* 1122 *argc()*
1113 argc() The result is the number of files in the argument list of the 1123 argc() The result is the number of files in the argument list of the
1114 current window. See |arglist|. 1124 current window. See |arglist|.
1115 1125
1642 {list1} and {list2} must be Lists. 1652 {list1} and {list2} must be Lists.
1643 Returns {list1}. 1653 Returns {list1}.
1644 Examples: > 1654 Examples: >
1645 :echo sort(extend(mylist, [7, 5])) 1655 :echo sort(extend(mylist, [7, 5]))
1646 :call extend(mylist, [2, 3], 1) 1656 :call extend(mylist, [2, 3], 1)
1647 < Use |append()| to concatenate one item to a list. To 1657 < Use |add()| to concatenate one item to a list. To concatenate
1648 concatenate two lists into a new list use the + operator: > 1658 two lists into a new list use the + operator: >
1649 :let newlist = [1, 2, 3] + [4, 5] 1659 :let newlist = [1, 2, 3] + [4, 5]
1650 1660
1651 filereadable({file}) *filereadable()* 1661 filereadable({file}) *filereadable()*
1652 The result is a Number, which is TRUE when a file with the 1662 The result is a Number, which is TRUE when a file with the
1653 name {file} exists, and can be read. If {file} doesn't exist, 1663 name {file} exists, and can be read. If {file} doesn't exist,
1741 allow a window to bring itself to the foreground. Use 1751 allow a window to bring itself to the foreground. Use
1742 |remote_foreground()| instead. 1752 |remote_foreground()| instead.
1743 {only in the Win32, Athena, Motif and GTK GUI versions and the 1753 {only in the Win32, Athena, Motif and GTK GUI versions and the
1744 Win32 console version} 1754 Win32 console version}
1745 1755
1756
1746 function({name}) *function()* 1757 function({name}) *function()*
1747 Return a Funcref variable that refers to function {name}. 1758 Return a Funcref variable that refers to function {name}.
1748 {name} can be a user defined function or an internal function. 1759 {name} can be a user defined function or an internal function.
1749 1760
1761
1762 get({list}, {idx} [, {default}]) *get*
1763 Get item {idx} from List {list}. When this item is not
1764 available return {default}. Return zero when {default} is
1765 omitted.
1766
1767 getbufvar({expr}, {varname}) *getbufvar()*
1768 The result is the value of option or local buffer variable
1769 {varname} in buffer {expr}. Note that the name without "b:"
1770 must be used.
1771 This also works for a global or local window option, but it
1772 doesn't work for a global or local window variable.
1773 For the use of {expr}, see |bufname()| above.
1774 When the buffer or variable doesn't exist an empty string is
1775 returned, there is no error message.
1776 Examples: >
1777 :let bufmodified = getbufvar(1, "&mod")
1778 :echo "todo myvar = " . getbufvar("todo", "myvar")
1779 <
1750 getchar([expr]) *getchar()* 1780 getchar([expr]) *getchar()*
1751 Get a single character from the user. If it is an 8-bit 1781 Get a single character from the user. If it is an 8-bit
1752 character, the result is a number. Otherwise a String is 1782 character, the result is a number. Otherwise a String is
1753 returned with the encoded character. For a special key it's a 1783 returned with the encoded character. For a special key it's a
1754 sequence of bytes starting with 0x80 (decimal: 128). 1784 sequence of bytes starting with 0x80 (decimal: 128).
1796 128 Macintosh only: command 1826 128 Macintosh only: command
1797 Only the modifiers that have not been included in the 1827 Only the modifiers that have not been included in the
1798 character itself are obtained. Thus Shift-a results in "A" 1828 character itself are obtained. Thus Shift-a results in "A"
1799 with no modifier. 1829 with no modifier.
1800 1830
1801 getbufvar({expr}, {varname}) *getbufvar()*
1802 The result is the value of option or local buffer variable
1803 {varname} in buffer {expr}. Note that the name without "b:"
1804 must be used.
1805 This also works for a global or local window option, but it
1806 doesn't work for a global or local window variable.
1807 For the use of {expr}, see |bufname()| above.
1808 When the buffer or variable doesn't exist an empty string is
1809 returned, there is no error message.
1810 Examples: >
1811 :let bufmodified = getbufvar(1, "&mod")
1812 :echo "todo myvar = " . getbufvar("todo", "myvar")
1813 <
1814 getcmdline() *getcmdline()* 1831 getcmdline() *getcmdline()*
1815 Return the current command-line. Only works when the command 1832 Return the current command-line. Only works when the command
1816 line is being edited, thus requires use of |c_CTRL-\_e| or 1833 line is being edited, thus requires use of |c_CTRL-\_e| or
1817 |c_CTRL-R_=|. 1834 |c_CTRL-R_=|.
1818 Example: > 1835 Example: >
1890 < Note that a type such as "link" will only be returned on 1907 < Note that a type such as "link" will only be returned on
1891 systems that support it. On some systems only "dir" and 1908 systems that support it. On some systems only "dir" and
1892 "file" are returned. 1909 "file" are returned.
1893 1910
1894 *getline()* 1911 *getline()*
1895 getline({lnum}) The result is a String, which is line {lnum} from the current 1912 getline({lnum} [, {end}])
1896 buffer. Example: > 1913 Without {end} the result is a String, which is line {lnum}
1914 from the current buffer. Example: >
1897 getline(1) 1915 getline(1)
1898 < When {lnum} is a String that doesn't start with a 1916 < When {lnum} is a String that doesn't start with a
1899 digit, line() is called to translate the String into a Number. 1917 digit, line() is called to translate the String into a Number.
1900 To get the line under the cursor: > 1918 To get the line under the cursor: >
1901 getline(".") 1919 getline(".")
1902 < When {lnum} is smaller than 1 or bigger than the number of 1920 < When {lnum} is smaller than 1 or bigger than the number of
1903 lines in the buffer, an empty string is returned. 1921 lines in the buffer, an empty string is returned.
1904 1922
1923 When {end} is given the result is a List where each item is a
1924 line from the current buffer in the range {lnum} to {end},
1925 including line {end}.
1926 {end} is used in the same way as {lnum}.
1927 Non-existing lines are silently omitted.
1928 When {end} is before {lnum} an error is given.
1929 Example: >
1930 :let start = line('.')
1931 :let end = search("^$") - 1
1932 :let lines = getline(start, end)
1933
1934
1905 getreg([{regname}]) *getreg()* 1935 getreg([{regname}]) *getreg()*
1906 The result is a String, which is the contents of register 1936 The result is a String, which is the contents of register
1907 {regname}. Example: > 1937 {regname}. Example: >
1908 :let cliptext = getreg('*') 1938 :let cliptext = getreg('*')
1909 < getreg('=') returns the last evaluated value of the expression 1939 < getreg('=') returns the last evaluated value of the expression
1910 register. (For use in maps). 1940 register. (For use in maps).
1911 If {regname} is not specified, |v:register| is used. 1941 If {regname} is not specified, |v:register| is used.
1942
1912 1943
1913 getregtype([{regname}]) *getregtype()* 1944 getregtype([{regname}]) *getregtype()*
1914 The result is a String, which is type of register {regname}. 1945 The result is a String, which is type of register {regname}.
1915 The value will be one of: 1946 The value will be one of:
1916 "v" for |characterwise| text 1947 "v" for |characterwise| text
1917 "V" for |linewise| text 1948 "V" for |linewise| text
1918 "<CTRL-V>{width}" for |blockwise-visual| text 1949 "<CTRL-V>{width}" for |blockwise-visual| text
1919 0 for an empty or unknown register 1950 0 for an empty or unknown register
1920 <CTRL-V> is one character with value 0x16. 1951 <CTRL-V> is one character with value 0x16.
1921 If {regname} is not specified, |v:register| is used. 1952 If {regname} is not specified, |v:register| is used.
1953
1922 1954
1923 *getwinposx()* 1955 *getwinposx()*
1924 getwinposx() The result is a Number, which is the X coordinate in pixels of 1956 getwinposx() The result is a Number, which is the X coordinate in pixels of
1925 the left hand side of the GUI Vim window. The result will be 1957 the left hand side of the GUI Vim window. The result will be
1926 -1 if the information is not available. 1958 -1 if the information is not available.
2216 |list-index|. -1 inserts just before the last item. 2248 |list-index|. -1 inserts just before the last item.
2217 Returns the resulting List. Examples: > 2249 Returns the resulting List. Examples: >
2218 :let mylist = insert([2, 3, 5], 1) 2250 :let mylist = insert([2, 3, 5], 1)
2219 :call insert(mylist, 4, -1) 2251 :call insert(mylist, 4, -1)
2220 :call insert(mylist, 6, len(mylist)) 2252 :call insert(mylist, 6, len(mylist))
2221 < The last example can be done simpler with |append()|. 2253 < The last example can be done simpler with |add()|.
2222 Note that when {item} is a List it is inserted as a single 2254 Note that when {item} is a List it is inserted as a single
2223 item. Use |extend()| to concatenate Lists. 2255 item. Use |extend()| to concatenate Lists.
2224 2256
2225 isdirectory({directory}) *isdirectory()* 2257 isdirectory({directory}) *isdirectory()*
2226 The result is a Number, which is non-zero when a directory 2258 The result is a Number, which is non-zero when a directory
2549 2581
2550 :autocmd NONE RemoteReply * 2582 :autocmd NONE RemoteReply *
2551 \ echo remote_read(expand("<amatch>")) 2583 \ echo remote_read(expand("<amatch>"))
2552 :echo remote_send("gvim", ":sleep 10 | echo ". 2584 :echo remote_send("gvim", ":sleep 10 | echo ".
2553 \ 'server2client(expand("<client>"), "HELLO")<CR>') 2585 \ 'server2client(expand("<client>"), "HELLO")<CR>')
2554 2586 <
2555
2556 remove({list}, {idx} [, {end}]) *remove()* 2587 remove({list}, {idx} [, {end}]) *remove()*
2557 Without {end}: Remove the item at {idx} from List {list} and 2588 Without {end}: Remove the item at {idx} from List {list} and
2558 return it. 2589 return it.
2559 With {end}: Remove items from {idx} to {end} (inclusive) and 2590 With {end}: Remove items from {idx} to {end} (inclusive) and
2560 return a list with these items. When {idx} points to the same 2591 return a list with these items. When {idx} points to the same
2581 When {expr} is a list the result is {expr} concatenated 2612 When {expr} is a list the result is {expr} concatenated
2582 {count} times. Example: > 2613 {count} times. Example: >
2583 :let longlist = repeat(['a', 'b'], 3) 2614 :let longlist = repeat(['a', 'b'], 3)
2584 < Results in ['a', 'b', 'a', 'b', 'a', 'b']. 2615 < Results in ['a', 'b', 'a', 'b', 'a', 'b'].
2585 2616
2617
2586 resolve({filename}) *resolve()* *E655* 2618 resolve({filename}) *resolve()* *E655*
2587 On MS-Windows, when {filename} is a shortcut (a .lnk file), 2619 On MS-Windows, when {filename} is a shortcut (a .lnk file),
2588 returns the path the shortcut points to in a simplified form. 2620 returns the path the shortcut points to in a simplified form.
2589 On Unix, repeat resolving symbolic links in all path 2621 On Unix, repeat resolving symbolic links in all path
2590 components of {filename} and return the simplified result. 2622 components of {filename} and return the simplified result.
2593 On other systems, return the simplified {filename}. 2625 On other systems, return the simplified {filename}.
2594 The simplification step is done as by |simplify()|. 2626 The simplification step is done as by |simplify()|.
2595 resolve() keeps a leading path component specifying the 2627 resolve() keeps a leading path component specifying the
2596 current directory (provided the result is still a relative 2628 current directory (provided the result is still a relative
2597 path name) and also keeps a trailing path separator. 2629 path name) and also keeps a trailing path separator.
2630
2631 *reverse()*
2632 reverse({list}) Reverse the order of items in {list} in-place. Returns
2633 {list}.
2634 If you want a list to remain unmodified make a copy first: >
2635 :let revlist = reverse(copy(mylist))
2598 2636
2599 search({pattern} [, {flags}]) *search()* 2637 search({pattern} [, {flags}]) *search()*
2600 Search for regexp pattern {pattern}. The search starts at the 2638 Search for regexp pattern {pattern}. The search starts at the
2601 cursor position. 2639 cursor position.
2602 {flags} is a String, which can contain these character flags: 2640 {flags} is a String, which can contain these character flags:
2817 a searchable directory or does not exist. On Unix, it is also 2855 a searchable directory or does not exist. On Unix, it is also
2818 removed when "dir" is a symbolic link within the same 2856 removed when "dir" is a symbolic link within the same
2819 directory. In order to resolve all the involved symbolic 2857 directory. In order to resolve all the involved symbolic
2820 links before simplifying the path name, use |resolve()|. 2858 links before simplifying the path name, use |resolve()|.
2821 2859
2860
2861 sort({list} [, {func}]) *sort()*
2862 Sort the items in {list} in-place. Returns {list}. If you
2863 want a list to remain unmodified make a copy first: >
2864 :let sortedlist = sort(copy(mylist))
2865 < Uses the string representation of each item to sort on.
2866 When {func} is given and it is one then case is ignored.
2867 When {func} is a Funcref or a function name, this function is
2868 called to compare items. The function is invoked with two
2869 items as argument and must return zero if they are equal, 1 if
2870 the first one sorts after the second one, -1 if the first one
2871 sorts before the second one. Example: >
2872 func MyCompare(i1, i2)
2873 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
2874 endfunc
2875 let sortedlist = sort(mylist, "MyCompare")
2876
2877 str2list({expr} [, {pattern}]) *str2list()*
2878 Make a List out of {expr}. When {pattern} is omitted each
2879 white-separated sequence of characters becomes an item.
2880 Otherwise the string is split where {pattern} matches,
2881 removing the matched characters. Empty strings are omitted.
2882 Example: >
2883 :let words = str2list(getline('.'), '\W\+')
2884 < Since empty strings are not added the "\+" isn't required but
2885 it makes the function work a bit faster.
2886
2887
2822 strftime({format} [, {time}]) *strftime()* 2888 strftime({format} [, {time}]) *strftime()*
2823 The result is a String, which is a formatted date and time, as 2889 The result is a String, which is a formatted date and time, as
2824 specified by the {format} string. The given {time} is used, 2890 specified by the {format} string. The given {time} is used,
2825 or the current time if no time is given. The accepted 2891 or the current time if no time is given. The accepted
2826 {format} depends on your system, thus this is not portable! 2892 {format} depends on your system, thus this is not portable!
2833 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25 2899 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
2834 :echo strftime("%y%m%d %T") 970427 11:53:55 2900 :echo strftime("%y%m%d %T") 970427 11:53:55
2835 :echo strftime("%H:%M") 11:55 2901 :echo strftime("%H:%M") 11:55
2836 :echo strftime("%c", getftime("file.c")) 2902 :echo strftime("%c", getftime("file.c"))
2837 Show mod time of file.c. 2903 Show mod time of file.c.
2838 < 2904 < Not available on all systems. To check use: >
2905 :if exists("*strftime")
2906
2839 stridx({haystack}, {needle}) *stridx()* 2907 stridx({haystack}, {needle}) *stridx()*
2840 The result is a Number, which gives the index in {haystack} of 2908 The result is a Number, which gives the index in {haystack} of
2841 the first occurrence of the String {needle} in the String 2909 the first occurrence of the String {needle} in the String
2842 {haystack}. The search is done case-sensitive. For advanced 2910 {haystack}. The search is done case-sensitive. For advanced
2843 searches use |match()|. 2911 searches use |match()|.