filter(mydict, 'v:key >= 8')
< Removes the items with a key below 8. >vim
call filter(var, 0)
< Removes all the items, thus clears the |List| or |Dictionary|.
Note that {expr2} is the result of expression and is then
used as an expression again. Often it is good to use a
|literal-string| to avoid having to double backslashes.
If {expr2} is a |Funcref| it must take two arguments:
1. the key or the index of the current item.
2. the value of the current item.
The function must return |TRUE| if the item should be kept.
Example that keeps the odd items of a list: >vim
func Odd(idx, val)
return a:idx % 2 == 1
endfunc
call filter(mylist, function('Odd'))
< It is shorter when using a |lambda|: >vim
call filter(myList, {idx, val -> idx * val <= 42})
< If you do not use "val" you can leave it out: >vim
call filter(myList, {idx -> idx % 2 == 1})
<
For a |List| and a |Dictionary| the operation is done
in-place. If you want it to remain unmodified make a copy
first: >vim
let l = filter(copy(mylist), 'v:val =~ "KEEP"')
< Returns {expr1}, the |List| or |Dictionary| that was filtered,
or a new |Blob| or |String|.
When an error is encountered while evaluating {expr2} no
further items in {expr1} are processed.
When {expr2} is a Funcref errors inside a function are ignored,
unless it was defined with the "abort" flag.
Parameters: ~
• {expr1} (`string|table`)
• {expr2} (`string|function`)
Return: ~
(`any`)
finddir({name} [, {path} [, {count}]]) *finddir()*
Find directory {name} in {path}. Supports both downwards and
upwards recursive directory searches. See |file-searching|
for the syntax of {path}.
Returns the path of the first found match. When the found
directory is below the current directory a relative path is
returned. Otherwise a full path is returned.
If {path} is omitted or empty then 'path' is used.
If the optional {count} is given, find {count}'s occurrence of
{name} in {path} instead of the first one.
When {count} is negative return all the matches in a |List|.
Returns an empty string if the directory is not found.
This is quite similar to the ex-command `:find`.
Parameters: ~
• {name} (`string`)
• {path} (`string?`)
• {count} (`integer?`)
Return: ~
(`string|string[]`)
findfile({name} [, {path} [, {count}]]) *findfile()*
Just like |finddir()|, but find a file instead of a directory.
Uses 'suffixesadd'.
Example: >vim
echo findfile("tags.vim", ".;")
< Searches from the directory of the current file upwards until
it finds the file "tags.vim".
Parameters: ~
• {name} (`string`)
• {path} (`string?`)
• {count} (`integer?`)
Return: ~
(`string|string[]`)
flatten({list} [, {maxdepth}]) *flatten()*
Flatten {list} up to {maxdepth} levels. Without {maxdepth}
the result is a |List| without nesting, as if {maxdepth} is
a very large number.
The {list} is changed in place, use |flattennew()| if you do
not want that.
*E900*
{maxdepth} means how deep in nested lists changes are made.
{list} is not modified when {maxdepth} is 0.
{maxdepth} must be positive number.
If there is an error the number zero is returned.
Example: >vim
echo flatten([1, [2, [3, 4]], 5])
< [1, 2, 3, 4, 5] >vim
echo flatten([1, [2, [3, 4]], 5], 1)
< [1, 2, [3, 4], 5]
Parameters: ~
• {list} (`any[]`)
• {maxdepth} (`integer?`)
Return: ~
(`any[]|0`)
flattennew({list} [, {maxdepth}]) *flattennew()*
Like |flatten()| but first