Vimscript: Filter a list (array) with an inline function

list_name->filter() filters the list list_name.

The filter function takes an inline function as a filter. The inline function syntax is { param1, param2 -> ... }

The filter function has the list index and value as parameters.

This example filters and gives you only the 2nd index of a list:

function Aa()
  let alist = ["one", "two", "three"]
  let alist = alist->filter({ i, line -> i == 1 })
  echo alist

:call Aa() will output ["two"].


Edit on github
comments powered by Disqus
Click me