Vim script で文字列内に一致する単語をカウント

組み込み関数で用意されていると思ったけど見当たらなかったので適当に自作。

[ソース]

function! s:matchcount(expr, pat, ...)
    let start = get(a:, "1", 0)
    let result = match(a:expr, a:pat, start)
    return result == -1 ? 0 : s:matchcount(a:expr, a:pat, result+1) + 1
endfunction

echo s:matchcount("aaaa b   aaa a", "a")
echo s:matchcount("hoge aahoge ahoge", "hoge")

[出力]

8
3


バッファ内の / の一致数数とかも取得したいなぁ。