Mercurial > vim
comparison runtime/doc/builtin.txt @ 34126:da670b1549b3 v9.1.0027
patch 9.1.0027: Vim is missing a foreach() func
Commit: https://github.com/vim/vim/commit/e79e2077607e8f829ba823308c91104a795736ba
Author: Ernie Rael <errael@raelity.com>
Date: Sat Jan 13 11:47:33 2024 +0100
patch 9.1.0027: Vim is missing a foreach() func
Problem: Vim is missing a foreach() func
Solution: Implement foreach({expr1}, {expr2}) function,
which applies {expr2} for each item in {expr1}
without changing it (Ernie Rael)
closes: #12166
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 13 Jan 2024 12:00:06 +0100 |
parents | 630e70746a1f |
children | 575b6a99b81c |
comparison
equal
deleted
inserted
replaced
34125:93171f4925c5 | 34126:da670b1549b3 |
---|---|
1 *builtin.txt* For Vim version 9.1. Last change: 2024 Jan 05 | 1 *builtin.txt* For Vim version 9.1. Last change: 2024 Jan 13 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
196 foldclosed({lnum}) Number first line of fold at {lnum} if closed | 196 foldclosed({lnum}) Number first line of fold at {lnum} if closed |
197 foldclosedend({lnum}) Number last line of fold at {lnum} if closed | 197 foldclosedend({lnum}) Number last line of fold at {lnum} if closed |
198 foldlevel({lnum}) Number fold level at {lnum} | 198 foldlevel({lnum}) Number fold level at {lnum} |
199 foldtext() String line displayed for closed fold | 199 foldtext() String line displayed for closed fold |
200 foldtextresult({lnum}) String text for closed fold at {lnum} | 200 foldtextresult({lnum}) String text for closed fold at {lnum} |
201 foreach({expr1}, {expr2}) List/Dict/Blob/String | |
202 for each item in {expr1} call {expr2} | |
201 foreground() Number bring the Vim window to the foreground | 203 foreground() Number bring the Vim window to the foreground |
202 fullcommand({name} [, {vim9}]) String get full command from {name} | 204 fullcommand({name} [, {vim9}]) String get full command from {name} |
203 funcref({name} [, {arglist}] [, {dict}]) | 205 funcref({name} [, {arglist}] [, {dict}]) |
204 Funcref reference to function {name} | 206 Funcref reference to function {name} |
205 function({name} [, {arglist}] [, {dict}]) | 207 function({name} [, {arglist}] [, {dict}]) |
2993 {not available when compiled without the |+folding| feature} | 2995 {not available when compiled without the |+folding| feature} |
2994 | 2996 |
2995 | 2997 |
2996 Can also be used as a |method|: > | 2998 Can also be used as a |method|: > |
2997 GetLnum()->foldtextresult() | 2999 GetLnum()->foldtextresult() |
3000 | |
3001 foreach({expr1}, {expr2}) *foreach()* | |
3002 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. | |
3003 For each item in {expr1} execute {expr2}. {expr1} is not | |
3004 modified; its values may be, as with |:lockvar| 1. *E741* | |
3005 See |map()| and |filter()| to modify {expr1}. | |
3006 | |
3007 {expr2} must be a |string| or |Funcref|. | |
3008 | |
3009 If {expr2} is a |string|, inside {expr2} |v:val| has the value | |
3010 of the current item. For a |Dictionary| |v:key| has the key | |
3011 of the current item and for a |List| |v:key| has the index of | |
3012 the current item. For a |Blob| |v:key| has the index of the | |
3013 current byte. For a |String| |v:key| has the index of the | |
3014 current character. | |
3015 Examples: > | |
3016 call foreach(mylist, 'used[v:val] = true') | |
3017 < This records the items that are in the {expr1} list. | |
3018 | |
3019 Note that {expr2} is the result of expression and is then used | |
3020 as a command. Often it is good to use a |literal-string| to | |
3021 avoid having to double backslashes. | |
3022 | |
3023 If {expr2} is a |Funcref| it must take two arguments: | |
3024 1. the key or the index of the current item. | |
3025 2. the value of the current item. | |
3026 With a legacy script lambda you don't get an error if it only | |
3027 accepts one argument, but with a Vim9 lambda you get "E1106: | |
3028 One argument too many", the number of arguments must match. | |
3029 If the function returns a value, it is ignored. | |
3030 | |
3031 Returns {expr1} in all cases. | |
3032 When an error is encountered while executing {expr2} no | |
3033 further items in {expr1} are processed. | |
3034 When {expr2} is a Funcref errors inside a function are ignored, | |
3035 unless it was defined with the "abort" flag. | |
3036 | |
3037 Can also be used as a |method|: > | |
3038 mylist->foreach(expr2) | |
2998 < | 3039 < |
2999 *foreground()* | 3040 *foreground()* |
3000 foreground() Move the Vim window to the foreground. Useful when sent from | 3041 foreground() Move the Vim window to the foreground. Useful when sent from |
3001 a client to a Vim server. |remote_send()| | 3042 a client to a Vim server. |remote_send()| |
3002 On Win32 systems this might not work, the OS does not always | 3043 On Win32 systems this might not work, the OS does not always |