filterを使います。
前回は:lsの結果をmapを2回繰り返して、buffer-listのファイル名を取得しましたが、
もう少し簡単に抽出してみます。
/tmp $ touch test_{1..5}.txt
/tmp $ vim test_*.txt
:let arr=split(execute('ls'),'"')
:echo arr

あとは、配列の奇数番目を抽出すれば良いですね。
:let i=0 :while i < len(arr) : if i % 2 == 1 : echo arr[i] : endif : let i=i+1 : endwhile

これをfilterを使って、もっとシンプルにしてみます。
filterのヘルプを確認。
:h filter(
filter({expr1}, {expr2}) *filter()*
{expr1} must be a |List| or a |Dictionary|.
For each item in {expr1} evaluate {expr2} and when the result
is zero remove the item from the |List| or |Dictionary|.
{expr2} must be a |string| or |Funcref|.
〜省略〜
Example that keeps the odd items of a list:
func Odd(idx, val)
return a:idx % 2 == 1
endfunc
call filter(mylist, function('Odd'))
It is shorter when using a |lambda|:
call filter(myList, {idx, val -> idx * val <= 42})
If you do not use "val" you can leave it out:
call filter(myList, {idx -> idx % 2 == 1})
ちょうど奇数抽出のことがExampleで述べられています。
これを使ってみます。
:let a=filter(arr,{idx -> idx % 2 == 1})
:echo a



コメント