(親記事はコチラ Vimコマンド&Script入門)
wordcount使います。
wordcount() *wordcount()*
The result is a dictionary of byte/chars/word statistics for
the current buffer. This is the same info as provided by
|g_CTRL-G|
The return value includes:
bytes Number of bytes in the buffer
chars Number of chars in the buffer
words Number of words in the buffer
cursor_bytes Number of bytes before cursor position
(not in Visual mode)
cursor_chars Number of chars before cursor position
(not in Visual mode)
cursor_words Number of words before cursor position
(not in Visual mode)
visual_bytes Number of bytes visually selected
(only in Visual mode)
visual_chars Number of chars visually selected
(only in Visual mode)
visual_words Number of words visually selected
(only in Visual mode)
とりあえず無名バッファを起動して確認。
/tmp $ vim
:echo wordcount()

各項目全部0です。
HELLOと書いてみます。
:echo wordcount()

それらしい数値になりました。
数字ではどうでしょう。HELLOの代わりに12345に書き換えます。
:echo wordcount()

数字に変えても同じでした。


コメント