Mercurial > vim
comparison runtime/doc/eval.txt @ 9422:f93704b11e43 v7.4.1992
commit https://github.com/vim/vim/commit/e381d3d5e098546854b008e01ca1d28ba1a4a057
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 7 14:50:41 2016 +0200
patch 7.4.1992
Problem: Values for true and false can be confusing.
Solution: Update the documentation. Add a test. Make v:true evaluate to
TRUE for a non-zero-arg.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 07 Jul 2016 15:00:07 +0200 |
parents | cbf052ccb120 |
children | e70fd2eb3ae1 |
comparison
equal
deleted
inserted
replaced
9421:ce8891614a89 | 9422:f93704b11e43 |
---|---|
1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 04 | 1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 06 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
98 < 64 ~ | 98 < 64 ~ |
99 | 99 |
100 To avoid a leading zero to cause octal conversion, or for using a different | 100 To avoid a leading zero to cause octal conversion, or for using a different |
101 base, use |str2nr()|. | 101 base, use |str2nr()|. |
102 | 102 |
103 *TRUE* *FALSE* | |
103 For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE. | 104 For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE. |
104 | 105 You can also use |v:false| and |v:true|. When TRUE is returned from a |
105 Note that in the command > | 106 function it is the Number one, FALSE is the number zero. |
107 | |
108 Note that in the command: > | |
106 :if "foo" | 109 :if "foo" |
107 "foo" is converted to 0, which means FALSE. To test for a non-empty string, | 110 :" NOT executed |
108 use empty(): > | 111 "foo" is converted to 0, which means FALSE. If the string starts with a |
112 non-zero number it means TRUE: > | |
113 :if "8foo" | |
114 :" executed | |
115 To test for a non-empty string, use empty(): > | |
109 :if !empty("foo") | 116 :if !empty("foo") |
110 < | 117 < |
118 *non-zero-arg* | |
119 Function arguments often behave slightly different from |TRUE|: If the | |
120 argument is present and it evaluates to a non-zero Number, |v:true| or a | |
121 non-empty String, then the value is considere to be TRUE. | |
122 Note that " " and "0" are also non-empty strings, thus cause the mode to be | |
123 cleared. A List, Dictionary or Float is not a Number or String, thus | |
124 evaluates to FALSE. | |
125 | |
111 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* | 126 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* |
112 List, Dictionary, Funcref and Job types are not automatically converted. | 127 List, Dictionary, Funcref and Job types are not automatically converted. |
113 | 128 |
114 *E805* *E806* *E808* | 129 *E805* *E806* *E808* |
115 When mixing Number and Float the Number is converted to Float. Otherwise | 130 When mixing Number and Float the Number is converted to Float. Otherwise |
692 ----- | 707 ----- |
693 | 708 |
694 expr2 ? expr1 : expr1 | 709 expr2 ? expr1 : expr1 |
695 | 710 |
696 The expression before the '?' is evaluated to a number. If it evaluates to | 711 The expression before the '?' is evaluated to a number. If it evaluates to |
697 non-zero, the result is the value of the expression between the '?' and ':', | 712 |TRUE|, the result is the value of the expression between the '?' and ':', |
698 otherwise the result is the value of the expression after the ':'. | 713 otherwise the result is the value of the expression after the ':'. |
699 Example: > | 714 Example: > |
700 :echo lnum == 1 ? "top" : lnum | 715 :echo lnum == 1 ? "top" : lnum |
701 | 716 |
702 Since the first expression is an "expr2", it cannot contain another ?:. The | 717 Since the first expression is an "expr2", it cannot contain another ?:. The |
720 | 735 |
721 *expr-barbar* *expr-&&* | 736 *expr-barbar* *expr-&&* |
722 The "||" and "&&" operators take one argument on each side. The arguments | 737 The "||" and "&&" operators take one argument on each side. The arguments |
723 are (converted to) Numbers. The result is: | 738 are (converted to) Numbers. The result is: |
724 | 739 |
725 input output ~ | 740 input output ~ |
726 n1 n2 n1 || n2 n1 && n2 ~ | 741 n1 n2 n1 || n2 n1 && n2 ~ |
727 zero zero zero zero | 742 |FALSE| |FALSE| |FALSE| |FALSE| |
728 zero non-zero non-zero zero | 743 |FALSE| |TRUE| |TRUE| |FALSE| |
729 non-zero zero non-zero zero | 744 |TRUE| |FALSE| |TRUE| |FALSE| |
730 non-zero non-zero non-zero non-zero | 745 |TRUE| |TRUE| |TRUE| |TRUE| |
731 | 746 |
732 The operators can be concatenated, for example: > | 747 The operators can be concatenated, for example: > |
733 | 748 |
734 &nu || &list && &shell == "csh" | 749 &nu || &list && &shell == "csh" |
735 | 750 |
741 arguments are not evaluated. This is like what happens in C. For example: > | 756 arguments are not evaluated. This is like what happens in C. For example: > |
742 | 757 |
743 let a = 1 | 758 let a = 1 |
744 echo a || b | 759 echo a || b |
745 | 760 |
746 This is valid even if there is no variable called "b" because "a" is non-zero, | 761 This is valid even if there is no variable called "b" because "a" is |TRUE|, |
747 so the result must be non-zero. Similarly below: > | 762 so the result must be |TRUE|. Similarly below: > |
748 | 763 |
749 echo exists("b") && b == "yes" | 764 echo exists("b") && b == "yes" |
750 | 765 |
751 This is valid whether "b" has been defined or not. The second clause will | 766 This is valid whether "b" has been defined or not. The second clause will |
752 only be evaluated if "b" has been defined. | 767 only be evaluated if "b" has been defined. |
909 ----- | 924 ----- |
910 ! expr7 logical NOT *expr-!* | 925 ! expr7 logical NOT *expr-!* |
911 - expr7 unary minus *expr-unary--* | 926 - expr7 unary minus *expr-unary--* |
912 + expr7 unary plus *expr-unary-+* | 927 + expr7 unary plus *expr-unary-+* |
913 | 928 |
914 For '!' non-zero becomes zero, zero becomes one. | 929 For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one). |
915 For '-' the sign of the number is changed. | 930 For '-' the sign of the number is changed. |
916 For '+' the number is unchanged. | 931 For '+' the number is unchanged. |
917 | 932 |
918 A String will be converted to a Number first. | 933 A String will be converted to a Number first. |
919 | 934 |
1881 atan({expr}) Float arc tangent of {expr} | 1896 atan({expr}) Float arc tangent of {expr} |
1882 atan2({expr}, {expr}) Float arc tangent of {expr1} / {expr2} | 1897 atan2({expr}, {expr}) Float arc tangent of {expr1} / {expr2} |
1883 browse({save}, {title}, {initdir}, {default}) | 1898 browse({save}, {title}, {initdir}, {default}) |
1884 String put up a file requester | 1899 String put up a file requester |
1885 browsedir({title}, {initdir}) String put up a directory requester | 1900 browsedir({title}, {initdir}) String put up a directory requester |
1886 bufexists({expr}) Number TRUE if buffer {expr} exists | 1901 bufexists({expr}) Number |TRUE| if buffer {expr} exists |
1887 buflisted({expr}) Number TRUE if buffer {expr} is listed | 1902 buflisted({expr}) Number |TRUE| if buffer {expr} is listed |
1888 bufloaded({expr}) Number TRUE if buffer {expr} is loaded | 1903 bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded |
1889 bufname({expr}) String Name of the buffer {expr} | 1904 bufname({expr}) String Name of the buffer {expr} |
1890 bufnr({expr} [, {create}]) Number Number of the buffer {expr} | 1905 bufnr({expr} [, {create}]) Number Number of the buffer {expr} |
1891 bufwinid({expr}) Number window ID of buffer {expr} | 1906 bufwinid({expr}) Number window ID of buffer {expr} |
1892 bufwinnr({expr}) Number window number of buffer {expr} | 1907 bufwinnr({expr}) Number window number of buffer {expr} |
1893 byte2line({byte}) Number line number at byte count {byte} | 1908 byte2line({byte}) Number line number at byte count {byte} |
1938 cursor({lnum}, {col} [, {off}]) | 1953 cursor({lnum}, {col} [, {off}]) |
1939 Number move cursor to {lnum}, {col}, {off} | 1954 Number move cursor to {lnum}, {col}, {off} |
1940 cursor({list}) Number move cursor to position in {list} | 1955 cursor({list}) Number move cursor to position in {list} |
1941 deepcopy({expr} [, {noref}]) any make a full copy of {expr} | 1956 deepcopy({expr} [, {noref}]) any make a full copy of {expr} |
1942 delete({fname} [, {flags}]) Number delete the file or directory {fname} | 1957 delete({fname} [, {flags}]) Number delete the file or directory {fname} |
1943 did_filetype() Number TRUE if FileType autocommand event used | 1958 did_filetype() Number |TRUE| if FileType autocmd event used |
1944 diff_filler({lnum}) Number diff filler lines about {lnum} | 1959 diff_filler({lnum}) Number diff filler lines about {lnum} |
1945 diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} | 1960 diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} |
1946 empty({expr}) Number TRUE if {expr} is empty | 1961 empty({expr}) Number |TRUE| if {expr} is empty |
1947 escape({string}, {chars}) String escape {chars} in {string} with '\' | 1962 escape({string}, {chars}) String escape {chars} in {string} with '\' |
1948 eval({string}) any evaluate {string} into its value | 1963 eval({string}) any evaluate {string} into its value |
1949 eventhandler() Number TRUE if inside an event handler | 1964 eventhandler() Number |TRUE| if inside an event handler |
1950 executable({expr}) Number 1 if executable {expr} exists | 1965 executable({expr}) Number 1 if executable {expr} exists |
1951 exepath({expr}) String full path of the command {expr} | 1966 exepath({expr}) String full path of the command {expr} |
1952 exists({expr}) Number TRUE if {expr} exists | 1967 exists({expr}) Number |TRUE| if {expr} exists |
1953 extend({expr1}, {expr2} [, {expr3}]) | 1968 extend({expr1}, {expr2} [, {expr3}]) |
1954 List/Dict insert items of {expr2} into {expr1} | 1969 List/Dict insert items of {expr2} into {expr1} |
1955 exp({expr}) Float exponential of {expr} | 1970 exp({expr}) Float exponential of {expr} |
1956 expand({expr} [, {nosuf} [, {list}]]) | 1971 expand({expr} [, {nosuf} [, {list}]]) |
1957 any expand special keywords in {expr} | 1972 any expand special keywords in {expr} |
1958 feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer | 1973 feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer |
1959 filereadable({file}) Number TRUE if {file} is a readable file | 1974 filereadable({file}) Number |TRUE| if {file} is a readable file |
1960 filewritable({file}) Number TRUE if {file} is a writable file | 1975 filewritable({file}) Number |TRUE| if {file} is a writable file |
1961 filter({expr}, {string}) List/Dict remove items from {expr} where | 1976 filter({expr}, {string}) List/Dict remove items from {expr} where |
1962 {string} is 0 | 1977 {string} is 0 |
1963 finddir({name}[, {path}[, {count}]]) | 1978 finddir({name}[, {path}[, {count}]]) |
1964 String find directory {name} in {path} | 1979 String find directory {name} in {path} |
1965 findfile({name}[, {path}[, {count}]]) | 1980 findfile({name}[, {path}[, {count}]]) |
2020 glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) | 2035 glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) |
2021 any expand file wildcards in {expr} | 2036 any expand file wildcards in {expr} |
2022 glob2regpat({expr}) String convert a glob pat into a search pat | 2037 glob2regpat({expr}) String convert a glob pat into a search pat |
2023 globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) | 2038 globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) |
2024 String do glob({expr}) for all dirs in {path} | 2039 String do glob({expr}) for all dirs in {path} |
2025 has({feature}) Number TRUE if feature {feature} supported | 2040 has({feature}) Number |TRUE| if feature {feature} supported |
2026 has_key({dict}, {key}) Number TRUE if {dict} has entry {key} | 2041 has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key} |
2027 haslocaldir([{winnr} [, {tabnr}]]) | 2042 haslocaldir([{winnr} [, {tabnr}]]) |
2028 Number TRUE if the window executed |:lcd| | 2043 Number |TRUE| if the window executed |:lcd| |
2029 hasmapto({what} [, {mode} [, {abbr}]]) | 2044 hasmapto({what} [, {mode} [, {abbr}]]) |
2030 Number TRUE if mapping to {what} exists | 2045 Number |TRUE| if mapping to {what} exists |
2031 histadd({history}, {item}) String add an item to a history | 2046 histadd({history}, {item}) String add an item to a history |
2032 histdel({history} [, {item}]) String remove an item from a history | 2047 histdel({history} [, {item}]) String remove an item from a history |
2033 histget({history} [, {index}]) String get the item {index} from a history | 2048 histget({history} [, {index}]) String get the item {index} from a history |
2034 histnr({history}) Number highest index of a history | 2049 histnr({history}) Number highest index of a history |
2035 hlexists({name}) Number TRUE if highlight group {name} exists | 2050 hlexists({name}) Number |TRUE| if highlight group {name} exists |
2036 hlID({name}) Number syntax ID of highlight group {name} | 2051 hlID({name}) Number syntax ID of highlight group {name} |
2037 hostname() String name of the machine Vim is running on | 2052 hostname() String name of the machine Vim is running on |
2038 iconv({expr}, {from}, {to}) String convert encoding of {expr} | 2053 iconv({expr}, {from}, {to}) String convert encoding of {expr} |
2039 indent({lnum}) Number indent of line {lnum} | 2054 indent({lnum}) Number indent of line {lnum} |
2040 index({list}, {expr} [, {start} [, {ic}]]) | 2055 index({list}, {expr} [, {start} [, {ic}]]) |
2047 inputrestore() Number restore typeahead | 2062 inputrestore() Number restore typeahead |
2048 inputsave() Number save and clear typeahead | 2063 inputsave() Number save and clear typeahead |
2049 inputsecret({prompt} [, {text}]) String like input() but hiding the text | 2064 inputsecret({prompt} [, {text}]) String like input() but hiding the text |
2050 insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] | 2065 insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] |
2051 invert({expr}) Number bitwise invert | 2066 invert({expr}) Number bitwise invert |
2052 isdirectory({directory}) Number TRUE if {directory} is a directory | 2067 isdirectory({directory}) Number |TRUE| if {directory} is a directory |
2053 islocked({expr}) Number TRUE if {expr} is locked | 2068 islocked({expr}) Number |TRUE| if {expr} is locked |
2054 isnan({expr}) Number TRUE if {expr} is NaN | 2069 isnan({expr}) Number |TRUE| if {expr} is NaN |
2055 items({dict}) List key-value pairs in {dict} | 2070 items({dict}) List key-value pairs in {dict} |
2056 job_getchannel({job}) Channel get the channel handle for {job} | 2071 job_getchannel({job}) Channel get the channel handle for {job} |
2057 job_info({job}) Dict get information about {job} | 2072 job_info({job}) Dict get information about {job} |
2058 job_setoptions({job}, {options}) none set options for {job} | 2073 job_setoptions({job}, {options}) none set options for {job} |
2059 job_start({command} [, {options}]) | 2074 job_start({command} [, {options}]) |
2436 |v:errors| when {pattern} matches {actual}. | 2451 |v:errors| when {pattern} matches {actual}. |
2437 | 2452 |
2438 assert_true({actual} [, {msg}]) *assert_true()* | 2453 assert_true({actual} [, {msg}]) *assert_true()* |
2439 When {actual} is not true an error message is added to | 2454 When {actual} is not true an error message is added to |
2440 |v:errors|, like with |assert_equal()|. | 2455 |v:errors|, like with |assert_equal()|. |
2441 A value is true when it is a non-zero number. When {actual} | 2456 A value is TRUE when it is a non-zero number. When {actual} |
2442 is not a number the assert fails. | 2457 is not a number the assert fails. |
2443 When {msg} is omitted an error in the form "Expected True but | 2458 When {msg} is omitted an error in the form "Expected True but |
2444 got {actual}" is produced. | 2459 got {actual}" is produced. |
2445 | 2460 |
2446 asin({expr}) *asin()* | 2461 asin({expr}) *asin()* |
2481 | 2496 |
2482 | 2497 |
2483 *browse()* | 2498 *browse()* |
2484 browse({save}, {title}, {initdir}, {default}) | 2499 browse({save}, {title}, {initdir}, {default}) |
2485 Put up a file requester. This only works when "has("browse")" | 2500 Put up a file requester. This only works when "has("browse")" |
2486 returns non-zero (only in some GUI versions). | 2501 returns |TRUE| (only in some GUI versions). |
2487 The input fields are: | 2502 The input fields are: |
2488 {save} when non-zero, select file to write | 2503 {save} when |TRUE|, select file to write |
2489 {title} title for the requester | 2504 {title} title for the requester |
2490 {initdir} directory to start browsing in | 2505 {initdir} directory to start browsing in |
2491 {default} default file name | 2506 {default} default file name |
2492 When the "Cancel" button is hit, something went wrong, or | 2507 When the "Cancel" button is hit, something went wrong, or |
2493 browsing is not possible, an empty string is returned. | 2508 browsing is not possible, an empty string is returned. |
2494 | 2509 |
2495 *browsedir()* | 2510 *browsedir()* |
2496 browsedir({title}, {initdir}) | 2511 browsedir({title}, {initdir}) |
2497 Put up a directory requester. This only works when | 2512 Put up a directory requester. This only works when |
2498 "has("browse")" returns non-zero (only in some GUI versions). | 2513 "has("browse")" returns |TRUE| (only in some GUI versions). |
2499 On systems where a directory browser is not supported a file | 2514 On systems where a directory browser is not supported a file |
2500 browser is used. In that case: select a file in the directory | 2515 browser is used. In that case: select a file in the directory |
2501 to be used. | 2516 to be used. |
2502 The input fields are: | 2517 The input fields are: |
2503 {title} title for the requester | 2518 {title} title for the requester |
2504 {initdir} directory to start browsing in | 2519 {initdir} directory to start browsing in |
2505 When the "Cancel" button is hit, something went wrong, or | 2520 When the "Cancel" button is hit, something went wrong, or |
2506 browsing is not possible, an empty string is returned. | 2521 browsing is not possible, an empty string is returned. |
2507 | 2522 |
2508 bufexists({expr}) *bufexists()* | 2523 bufexists({expr}) *bufexists()* |
2509 The result is a Number, which is non-zero if a buffer called | 2524 The result is a Number, which is |TRUE| if a buffer called |
2510 {expr} exists. | 2525 {expr} exists. |
2511 If the {expr} argument is a number, buffer numbers are used. | 2526 If the {expr} argument is a number, buffer numbers are used. |
2512 If the {expr} argument is a string it must match a buffer name | 2527 If the {expr} argument is a string it must match a buffer name |
2513 exactly. The name can be: | 2528 exactly. The name can be: |
2514 - Relative to the current directory. | 2529 - Relative to the current directory. |
2526 file name. | 2541 file name. |
2527 *buffer_exists()* | 2542 *buffer_exists()* |
2528 Obsolete name: buffer_exists(). | 2543 Obsolete name: buffer_exists(). |
2529 | 2544 |
2530 buflisted({expr}) *buflisted()* | 2545 buflisted({expr}) *buflisted()* |
2531 The result is a Number, which is non-zero if a buffer called | 2546 The result is a Number, which is |TRUE| if a buffer called |
2532 {expr} exists and is listed (has the 'buflisted' option set). | 2547 {expr} exists and is listed (has the 'buflisted' option set). |
2533 The {expr} argument is used like with |bufexists()|. | 2548 The {expr} argument is used like with |bufexists()|. |
2534 | 2549 |
2535 bufloaded({expr}) *bufloaded()* | 2550 bufloaded({expr}) *bufloaded()* |
2536 The result is a Number, which is non-zero if a buffer called | 2551 The result is a Number, which is |TRUE| if a buffer called |
2537 {expr} exists and is loaded (shown in a window or hidden). | 2552 {expr} exists and is loaded (shown in a window or hidden). |
2538 The {expr} argument is used like with |bufexists()|. | 2553 The {expr} argument is used like with |bufexists()|. |
2539 | 2554 |
2540 bufname({expr}) *bufname()* | 2555 bufname({expr}) *bufname()* |
2541 The result is the name of a buffer, as it is displayed by the | 2556 The result is the name of a buffer, as it is displayed by the |
2783 the same as one item in the list that 'omnifunc' would return. | 2798 the same as one item in the list that 'omnifunc' would return. |
2784 | 2799 |
2785 complete_check() *complete_check()* | 2800 complete_check() *complete_check()* |
2786 Check for a key typed while looking for completion matches. | 2801 Check for a key typed while looking for completion matches. |
2787 This is to be used when looking for matches takes some time. | 2802 This is to be used when looking for matches takes some time. |
2788 Returns non-zero when searching for matches is to be aborted, | 2803 Returns |TRUE| when searching for matches is to be aborted, |
2789 zero otherwise. | 2804 zero otherwise. |
2790 Only to be used by the function specified with the | 2805 Only to be used by the function specified with the |
2791 'completefunc' option. | 2806 'completefunc' option. |
2792 | 2807 |
2793 *confirm()* | 2808 *confirm()* |
3043 count({comp}, {expr} [, {ic} [, {start}]]) *count()* | 3058 count({comp}, {expr} [, {ic} [, {start}]]) *count()* |
3044 Return the number of times an item with value {expr} appears | 3059 Return the number of times an item with value {expr} appears |
3045 in |List| or |Dictionary| {comp}. | 3060 in |List| or |Dictionary| {comp}. |
3046 If {start} is given then start with the item with this index. | 3061 If {start} is given then start with the item with this index. |
3047 {start} can only be used with a |List|. | 3062 {start} can only be used with a |List|. |
3048 When {ic} is given and it's non-zero then case is ignored. | 3063 When {ic} is given and it's |TRUE| then case is ignored. |
3049 | 3064 |
3050 | 3065 |
3051 *cscope_connection()* | 3066 *cscope_connection()* |
3052 cscope_connection([{num} , {dbpath} [, {prepend}]]) | 3067 cscope_connection([{num} , {dbpath} [, {prepend}]]) |
3053 Checks for the existence of a |cscope| connection. If no | 3068 Checks for the existence of a |cscope| connection. If no |
3157 Use |remove()| to delete an item from a |List|. | 3172 Use |remove()| to delete an item from a |List|. |
3158 To delete a line from the buffer use |:delete|. Use |:exe| | 3173 To delete a line from the buffer use |:delete|. Use |:exe| |
3159 when the line number is in a variable. | 3174 when the line number is in a variable. |
3160 | 3175 |
3161 *did_filetype()* | 3176 *did_filetype()* |
3162 did_filetype() Returns non-zero when autocommands are being executed and the | 3177 did_filetype() Returns |TRUE| when autocommands are being executed and the |
3163 FileType event has been triggered at least once. Can be used | 3178 FileType event has been triggered at least once. Can be used |
3164 to avoid triggering the FileType event again in the scripts | 3179 to avoid triggering the FileType event again in the scripts |
3165 that detect the file type. |FileType| | 3180 that detect the file type. |FileType| |
3166 When editing another file, the counter is reset, thus this | 3181 When editing another file, the counter is reset, thus this |
3167 really checks if the FileType event has been triggered for the | 3182 really checks if the FileType event has been triggered for the |
3254 echo exepath(v:progpath) | 3269 echo exepath(v:progpath) |
3255 < If {expr} cannot be found in $PATH or is not executable then | 3270 < If {expr} cannot be found in $PATH or is not executable then |
3256 an empty string is returned. | 3271 an empty string is returned. |
3257 | 3272 |
3258 *exists()* | 3273 *exists()* |
3259 exists({expr}) The result is a Number, which is non-zero if {expr} is | 3274 exists({expr}) The result is a Number, which is |TRUE| if {expr} is |
3260 defined, zero otherwise. The {expr} argument is a string, | 3275 defined, zero otherwise. The {expr} argument is a string, |
3261 which contains one of these: | 3276 which contains one of these: |
3262 &option-name Vim option (only checks if it exists, | 3277 &option-name Vim option (only checks if it exists, |
3263 not if it really works) | 3278 not if it really works) |
3264 +option-name Vim option that works. | 3279 +option-name Vim option that works. |
3351 | 3366 |
3352 expand({expr} [, {nosuf} [, {list}]]) *expand()* | 3367 expand({expr} [, {nosuf} [, {list}]]) *expand()* |
3353 Expand wildcards and the following special keywords in {expr}. | 3368 Expand wildcards and the following special keywords in {expr}. |
3354 'wildignorecase' applies. | 3369 'wildignorecase' applies. |
3355 | 3370 |
3356 If {list} is given and it is non-zero, a List will be returned. | 3371 If {list} is given and it is |TRUE|, a List will be returned. |
3357 Otherwise the result is a String and when there are several | 3372 Otherwise the result is a String and when there are several |
3358 matches, they are separated by <NL> characters. [Note: in | 3373 matches, they are separated by <NL> characters. [Note: in |
3359 version 5.0 a space was used, which caused problems when a | 3374 version 5.0 a space was used, which caused problems when a |
3360 file name contains a space] | 3375 file name contains a space] |
3361 | 3376 |
3410 '/' added. | 3425 '/' added. |
3411 | 3426 |
3412 When {expr} does not start with '%', '#' or '<', it is | 3427 When {expr} does not start with '%', '#' or '<', it is |
3413 expanded like a file name is expanded on the command line. | 3428 expanded like a file name is expanded on the command line. |
3414 'suffixes' and 'wildignore' are used, unless the optional | 3429 'suffixes' and 'wildignore' are used, unless the optional |
3415 {nosuf} argument is given and it is non-zero. | 3430 {nosuf} argument is given and it is |TRUE|. |
3416 Names for non-existing files are included. The "**" item can | 3431 Names for non-existing files are included. The "**" item can |
3417 be used to search in a directory tree. For example, to find | 3432 be used to search in a directory tree. For example, to find |
3418 all "README" files in the current directory and below: > | 3433 all "README" files in the current directory and below: > |
3419 :echo expand("**/README") | 3434 :echo expand("**/README") |
3420 < | 3435 < |
3502 a little later. Useful for testing CursorHoldI. | 3517 a little later. Useful for testing CursorHoldI. |
3503 | 3518 |
3504 Return value is always 0. | 3519 Return value is always 0. |
3505 | 3520 |
3506 filereadable({file}) *filereadable()* | 3521 filereadable({file}) *filereadable()* |
3507 The result is a Number, which is TRUE when a file with the | 3522 The result is a Number, which is |TRUE| when a file with the |
3508 name {file} exists, and can be read. If {file} doesn't exist, | 3523 name {file} exists, and can be read. If {file} doesn't exist, |
3509 or is a directory, the result is FALSE. {file} is any | 3524 or is a directory, the result is |FALSE|. {file} is any |
3510 expression, which is used as a String. | 3525 expression, which is used as a String. |
3511 If you don't care about the file being readable you can use | 3526 If you don't care about the file being readable you can use |
3512 |glob()|. | 3527 |glob()|. |
3513 *file_readable()* | 3528 *file_readable()* |
3514 Obsolete name: file_readable(). | 3529 Obsolete name: file_readable(). |
3543 |literal-string| to avoid having to double backslashes. | 3558 |literal-string| to avoid having to double backslashes. |
3544 | 3559 |
3545 If {expr2} is a |Funcref| it must take two arguments: | 3560 If {expr2} is a |Funcref| it must take two arguments: |
3546 1. the key or the index of the current item. | 3561 1. the key or the index of the current item. |
3547 2. the value of the current item. | 3562 2. the value of the current item. |
3548 The function must return TRUE if the item should be kept. | 3563 The function must return |TRUE| if the item should be kept. |
3549 Example that keeps the odd items of a list: > | 3564 Example that keeps the odd items of a list: > |
3550 func Odd(idx, val) | 3565 func Odd(idx, val) |
3551 return a:idx % 2 == 1 | 3566 return a:idx % 2 == 1 |
3552 endfunc | 3567 endfunc |
3553 call filter(mylist, function('Odd')) | 3568 call filter(mylist, function('Odd')) |
4183 list item is a dictionary with these entries: | 4198 list item is a dictionary with these entries: |
4184 bufnr number of buffer that has the file name, use | 4199 bufnr number of buffer that has the file name, use |
4185 bufname() to get the name | 4200 bufname() to get the name |
4186 lnum line number in the buffer (first line is 1) | 4201 lnum line number in the buffer (first line is 1) |
4187 col column number (first column is 1) | 4202 col column number (first column is 1) |
4188 vcol non-zero: "col" is visual column | 4203 vcol |TRUE|: "col" is visual column |
4189 zero: "col" is byte index | 4204 |FALSE|: "col" is byte index |
4190 nr error number | 4205 nr error number |
4191 pattern search pattern used to locate the error | 4206 pattern search pattern used to locate the error |
4192 text description of the error | 4207 text description of the error |
4193 type type of the error, 'E', '1', etc. | 4208 type type of the error, 'E', '1', etc. |
4194 valid non-zero: recognized error message | 4209 valid |TRUE|: recognized error message |
4195 | 4210 |
4196 When there is no error list or it's empty an empty list is | 4211 When there is no error list or it's empty an empty list is |
4197 returned. Quickfix list entries with non-existing buffer | 4212 returned. Quickfix list entries with non-existing buffer |
4198 number are returned with "bufnr" set to zero. | 4213 number are returned with "bufnr" set to zero. |
4199 | 4214 |
4215 register. (For use in maps.) | 4230 register. (For use in maps.) |
4216 getreg('=', 1) returns the expression itself, so that it can | 4231 getreg('=', 1) returns the expression itself, so that it can |
4217 be restored with |setreg()|. For other registers the extra | 4232 be restored with |setreg()|. For other registers the extra |
4218 argument is ignored, thus you can always give it. | 4233 argument is ignored, thus you can always give it. |
4219 | 4234 |
4220 If {list} is present and non-zero, the result type is changed | 4235 If {list} is present and |TRUE|, the result type is changed |
4221 to |List|. Each list item is one text line. Use it if you care | 4236 to |List|. Each list item is one text line. Use it if you care |
4222 about zero bytes possibly present inside register: without | 4237 about zero bytes possibly present inside register: without |
4223 third argument both NLs and zero bytes are represented as NLs | 4238 third argument both NLs and zero bytes are represented as NLs |
4224 (see |NL-used-for-Nul|). | 4239 (see |NL-used-for-Nul|). |
4225 When the register was not set an empty list is returned. | 4240 When the register was not set an empty list is returned. |
4286 < | 4301 < |
4287 glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* | 4302 glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* |
4288 Expand the file wildcards in {expr}. See |wildcards| for the | 4303 Expand the file wildcards in {expr}. See |wildcards| for the |
4289 use of special characters. | 4304 use of special characters. |
4290 | 4305 |
4291 Unless the optional {nosuf} argument is given and is non-zero, | 4306 Unless the optional {nosuf} argument is given and is |TRUE|, |
4292 the 'suffixes' and 'wildignore' options apply: Names matching | 4307 the 'suffixes' and 'wildignore' options apply: Names matching |
4293 one of the patterns in 'wildignore' will be skipped and | 4308 one of the patterns in 'wildignore' will be skipped and |
4294 'suffixes' affect the ordering of matches. | 4309 'suffixes' affect the ordering of matches. |
4295 'wildignorecase' always applies. | 4310 'wildignorecase' always applies. |
4296 | 4311 |
4297 When {list} is present and it is non-zero the result is a List | 4312 When {list} is present and it is |TRUE| the result is a List |
4298 with all matching files. The advantage of using a List is, | 4313 with all matching files. The advantage of using a List is, |
4299 you also get filenames containing newlines correctly. | 4314 you also get filenames containing newlines correctly. |
4300 Otherwise the result is a String and when there are several | 4315 Otherwise the result is a String and when there are several |
4301 matches, they are separated by <NL> characters. | 4316 matches, they are separated by <NL> characters. |
4302 | 4317 |
4303 If the expansion fails, the result is an empty String or List. | 4318 If the expansion fails, the result is an empty String or List. |
4304 | 4319 |
4305 A name for a non-existing file is not included. A symbolic | 4320 A name for a non-existing file is not included. A symbolic |
4306 link is only included if it points to an existing file. | 4321 link is only included if it points to an existing file. |
4307 However, when the {alllinks} argument is present and it is | 4322 However, when the {alllinks} argument is present and it is |
4308 non-zero then all symbolic links are included. | 4323 |TRUE| then all symbolic links are included. |
4309 | 4324 |
4310 For most systems backticks can be used to get files names from | 4325 For most systems backticks can be used to get files names from |
4311 any external command. Example: > | 4326 any external command. Example: > |
4312 :let tagfiles = glob("`find . -name tags -print`") | 4327 :let tagfiles = glob("`find . -name tags -print`") |
4313 :let &tags = substitute(tagfiles, "\n", ",", "g") | 4328 :let &tags = substitute(tagfiles, "\n", ",", "g") |
4340 backslash. Note that on MS-Windows a directory may have a | 4355 backslash. Note that on MS-Windows a directory may have a |
4341 trailing backslash, remove it if you put a comma after it. | 4356 trailing backslash, remove it if you put a comma after it. |
4342 If the expansion fails for one of the directories, there is no | 4357 If the expansion fails for one of the directories, there is no |
4343 error message. | 4358 error message. |
4344 | 4359 |
4345 Unless the optional {nosuf} argument is given and is non-zero, | 4360 Unless the optional {nosuf} argument is given and is |TRUE|, |
4346 the 'suffixes' and 'wildignore' options apply: Names matching | 4361 the 'suffixes' and 'wildignore' options apply: Names matching |
4347 one of the patterns in 'wildignore' will be skipped and | 4362 one of the patterns in 'wildignore' will be skipped and |
4348 'suffixes' affect the ordering of matches. | 4363 'suffixes' affect the ordering of matches. |
4349 | 4364 |
4350 When {list} is present and it is non-zero the result is a List | 4365 When {list} is present and it is |TRUE| the result is a List |
4351 with all matching files. The advantage of using a List is, you | 4366 with all matching files. The advantage of using a List is, you |
4352 also get filenames containing newlines correctly. Otherwise | 4367 also get filenames containing newlines correctly. Otherwise |
4353 the result is a String and when there are several matches, | 4368 the result is a String and when there are several matches, |
4354 they are separated by <NL> characters. Example: > | 4369 they are separated by <NL> characters. Example: > |
4355 :echo globpath(&rtp, "syntax/c.vim", 0, 1) | 4370 :echo globpath(&rtp, "syntax/c.vim", 0, 1) |
4388 hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* | 4403 hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* |
4389 The result is a Number, which is 1 if there is a mapping that | 4404 The result is a Number, which is 1 if there is a mapping that |
4390 contains {what} in somewhere in the rhs (what it is mapped to) | 4405 contains {what} in somewhere in the rhs (what it is mapped to) |
4391 and this mapping exists in one of the modes indicated by | 4406 and this mapping exists in one of the modes indicated by |
4392 {mode}. | 4407 {mode}. |
4393 When {abbr} is there and it is non-zero use abbreviations | 4408 When {abbr} is there and it is |TRUE| use abbreviations |
4394 instead of mappings. Don't forget to specify Insert and/or | 4409 instead of mappings. Don't forget to specify Insert and/or |
4395 Command-line mode. | 4410 Command-line mode. |
4396 Both the global mappings and the mappings local to the current | 4411 Both the global mappings and the mappings local to the current |
4397 buffer are checked for a match. | 4412 buffer are checked for a match. |
4398 If no matching mapping is found 0 is returned. | 4413 If no matching mapping is found 0 is returned. |
4547 the String "4" is different from the Number 4. And the number | 4562 the String "4" is different from the Number 4. And the number |
4548 4 is different from the Float 4.0. The value of 'ignorecase' | 4563 4 is different from the Float 4.0. The value of 'ignorecase' |
4549 is not used here, case always matters. | 4564 is not used here, case always matters. |
4550 If {start} is given then start looking at the item with index | 4565 If {start} is given then start looking at the item with index |
4551 {start} (may be negative for an item relative to the end). | 4566 {start} (may be negative for an item relative to the end). |
4552 When {ic} is given and it is non-zero, ignore case. Otherwise | 4567 When {ic} is given and it is |TRUE|, ignore case. Otherwise |
4553 case must match. | 4568 case must match. |
4554 -1 is returned when {expr} is not found in {list}. | 4569 -1 is returned when {expr} is not found in {list}. |
4555 Example: > | 4570 Example: > |
4556 :let idx = index(words, "the") | 4571 :let idx = index(words, "the") |
4557 :if index(numbers, 123) >= 0 | 4572 :if index(numbers, 123) >= 0 |
4675 Bitwise invert. The argument is converted to a number. A | 4690 Bitwise invert. The argument is converted to a number. A |
4676 List, Dict or Float argument causes an error. Example: > | 4691 List, Dict or Float argument causes an error. Example: > |
4677 :let bits = invert(bits) | 4692 :let bits = invert(bits) |
4678 | 4693 |
4679 isdirectory({directory}) *isdirectory()* | 4694 isdirectory({directory}) *isdirectory()* |
4680 The result is a Number, which is non-zero when a directory | 4695 The result is a Number, which is |TRUE| when a directory |
4681 with the name {directory} exists. If {directory} doesn't | 4696 with the name {directory} exists. If {directory} doesn't |
4682 exist, or isn't a directory, the result is FALSE. {directory} | 4697 exist, or isn't a directory, the result is |FALSE|. {directory} |
4683 is any expression, which is used as a String. | 4698 is any expression, which is used as a String. |
4684 | 4699 |
4685 islocked({expr}) *islocked()* *E786* | 4700 islocked({expr}) *islocked()* *E786* |
4686 The result is a Number, which is non-zero when {expr} is the | 4701 The result is a Number, which is |TRUE| when {expr} is the |
4687 name of a locked variable. | 4702 name of a locked variable. |
4688 {expr} must be the name of a variable, |List| item or | 4703 {expr} must be the name of a variable, |List| item or |
4689 |Dictionary| entry, not the variable itself! Example: > | 4704 |Dictionary| entry, not the variable itself! Example: > |
4690 :let alist = [0, ['a', 'b'], 2, 3] | 4705 :let alist = [0, ['a', 'b'], 2, 3] |
4691 :lockvar 1 alist | 4706 :lockvar 1 alist |
4694 | 4709 |
4695 < When {expr} is a variable that does not exist you get an error | 4710 < When {expr} is a variable that does not exist you get an error |
4696 message. Use |exists()| to check for existence. | 4711 message. Use |exists()| to check for existence. |
4697 | 4712 |
4698 isnan({expr}) *isnan()* | 4713 isnan({expr}) *isnan()* |
4699 Return non-zero if {expr} is a float with value NaN. > | 4714 Return |TRUE| if {expr} is a float with value NaN. > |
4700 echo isnan(0.0 / 0.0) | 4715 echo isnan(0.0 / 0.0) |
4701 < 1 ~ | 4716 < 1 ~ |
4702 | 4717 |
4703 {only available when compiled with the |+float| feature} | 4718 {only available when compiled with the |+float| feature} |
4704 | 4719 |
5112 "x" Visual | 5127 "x" Visual |
5113 "l" langmap |language-mapping| | 5128 "l" langmap |language-mapping| |
5114 "" Normal, Visual and Operator-pending | 5129 "" Normal, Visual and Operator-pending |
5115 When {mode} is omitted, the modes for "" are used. | 5130 When {mode} is omitted, the modes for "" are used. |
5116 | 5131 |
5117 When {abbr} is there and it is non-zero use abbreviations | 5132 When {abbr} is there and it is |TRUE| use abbreviations |
5118 instead of mappings. | 5133 instead of mappings. |
5119 | 5134 |
5120 When {dict} is there and it is non-zero return a dictionary | 5135 When {dict} is there and it is |TRUE| return a dictionary |
5121 containing all the information of the mapping with the | 5136 containing all the information of the mapping with the |
5122 following items: | 5137 following items: |
5123 "lhs" The {lhs} of the mapping. | 5138 "lhs" The {lhs} of the mapping. |
5124 "rhs" The {rhs} of the mapping as typed. | 5139 "rhs" The {rhs} of the mapping as typed. |
5125 "silent" 1 for a |:map-silent| mapping, else 0. | 5140 "silent" 1 for a |:map-silent| mapping, else 0. |
5146 | 5161 |
5147 mapcheck({name}[, {mode} [, {abbr}]]) *mapcheck()* | 5162 mapcheck({name}[, {mode} [, {abbr}]]) *mapcheck()* |
5148 Check if there is a mapping that matches with {name} in mode | 5163 Check if there is a mapping that matches with {name} in mode |
5149 {mode}. See |maparg()| for {mode} and special names in | 5164 {mode}. See |maparg()| for {mode} and special names in |
5150 {name}. | 5165 {name}. |
5151 When {abbr} is there and it is non-zero use abbreviations | 5166 When {abbr} is there and it is |TRUE| use abbreviations |
5152 instead of mappings. | 5167 instead of mappings. |
5153 A match happens with a mapping that starts with {name} and | 5168 A match happens with a mapping that starts with {name} and |
5154 with a mapping which is equal to the start of {name}. | 5169 with a mapping which is equal to the start of {name}. |
5155 | 5170 |
5156 matches mapping "a" "ab" "abc" ~ | 5171 matches mapping "a" "ab" "abc" ~ |
5428 < | 5443 < |
5429 *mode()* | 5444 *mode()* |
5430 mode([expr]) Return a string that indicates the current mode. | 5445 mode([expr]) Return a string that indicates the current mode. |
5431 If [expr] is supplied and it evaluates to a non-zero Number or | 5446 If [expr] is supplied and it evaluates to a non-zero Number or |
5432 a non-empty String (|non-zero-arg|), then the full mode is | 5447 a non-empty String (|non-zero-arg|), then the full mode is |
5433 returned, otherwise only the first letter is returned. Note | 5448 returned, otherwise only the first letter is returned. |
5434 that " " and "0" are also non-empty strings. | |
5435 | 5449 |
5436 n Normal | 5450 n Normal |
5437 no Operator-pending | 5451 no Operator-pending |
5438 v Visual by character | 5452 v Visual by character |
5439 V Visual by line | 5453 V Visual by line |
6539 shellescape({string} [, {special}]) *shellescape()* | 6553 shellescape({string} [, {special}]) *shellescape()* |
6540 Escape {string} for use as a shell command argument. | 6554 Escape {string} for use as a shell command argument. |
6541 On MS-Windows and MS-DOS, when 'shellslash' is not set, it | 6555 On MS-Windows and MS-DOS, when 'shellslash' is not set, it |
6542 will enclose {string} in double quotes and double all double | 6556 will enclose {string} in double quotes and double all double |
6543 quotes within {string}. | 6557 quotes within {string}. |
6544 For other systems, it will enclose {string} in single quotes | 6558 Otherwise it will enclose {string} in single quotes and |
6545 and replace all "'" with "'\''". | 6559 replace all "'" with "'\''". |
6546 When the {special} argument is present and it's a non-zero | 6560 When the {special} argument is present and it's a non-zero |
6547 Number or a non-empty String (|non-zero-arg|), then special | 6561 Number or a non-empty String (|non-zero-arg|), then special |
6548 items such as "!", "%", "#" and "<cword>" will be preceded by | 6562 items such as "!", "%", "#" and "<cword>" will be preceded by |
6549 a backslash. This backslash will be removed again by the |:!| | 6563 a backslash. This backslash will be removed again by the |:!| |
6550 command. | 6564 command. |
7292 | 7306 |
7293 | 7307 |
7294 *test_disable_char_avail()* | 7308 *test_disable_char_avail()* |
7295 test_disable_char_avail({expr}) | 7309 test_disable_char_avail({expr}) |
7296 When {expr} is 1 the internal char_avail() function will | 7310 When {expr} is 1 the internal char_avail() function will |
7297 return FALSE. When {expr} is 0 the char_avail() function will | 7311 return |FALSE|. When {expr} is 0 the char_avail() function will |
7298 function normally. | 7312 function normally. |
7299 Only use this for a test where typeahead causes the test not | 7313 Only use this for a test where typeahead causes the test not |
7300 to work. E.g., to trigger the CursorMovedI autocommand event. | 7314 to work. E.g., to trigger the CursorMovedI autocommand event. |
7301 | 7315 |
7302 test_garbagecollect_now() *test_garbagecollect_now()* | 7316 test_garbagecollect_now() *test_garbagecollect_now()* |
7541 < This enters the same Visual mode as before. It is also useful | 7555 < This enters the same Visual mode as before. It is also useful |
7542 in scripts if you wish to act differently depending on the | 7556 in scripts if you wish to act differently depending on the |
7543 Visual mode that was used. | 7557 Visual mode that was used. |
7544 If Visual mode is active, use |mode()| to get the Visual mode | 7558 If Visual mode is active, use |mode()| to get the Visual mode |
7545 (e.g., in a |:vmap|). | 7559 (e.g., in a |:vmap|). |
7546 *non-zero-arg* | |
7547 If [expr] is supplied and it evaluates to a non-zero Number or | 7560 If [expr] is supplied and it evaluates to a non-zero Number or |
7548 a non-empty String, then the Visual mode will be cleared and | 7561 a non-empty String, then the Visual mode will be cleared and |
7549 the old value is returned. Note that " " and "0" are also | 7562 the old value is returned. See |non-zero-arg|. |
7550 non-empty strings, thus cause the mode to be cleared. A List, | |
7551 Dictionary or Float is not a Number or String, thus does not | |
7552 cause the mode to be cleared. | |
7553 | 7563 |
7554 wildmenumode() *wildmenumode()* | 7564 wildmenumode() *wildmenumode()* |
7555 Returns non-zero when the wildmenu is active and zero | 7565 Returns |TRUE| when the wildmenu is active and |FALSE| |
7556 otherwise. See 'wildmenu' and 'wildmode'. | 7566 otherwise. See 'wildmenu' and 'wildmode'. |
7557 This can be used in mappings to handle the 'wildcharm' option | 7567 This can be used in mappings to handle the 'wildcharm' option |
7558 gracefully. (Makes only sense with |mapmode-c| mappings). | 7568 gracefully. (Makes only sense with |mapmode-c| mappings). |
7559 | 7569 |
7560 For example to make <c-j> work like <down> in wildmode, use: > | 7570 For example to make <c-j> work like <down> in wildmode, use: > |