I can get a word count of a range of lines, by doing something like this:
:1,20w !wc -w
(where that gets lines 1 to 20, writes (w
) them to the external shell command (!
) wc -w
, and outputs the result in the info area.
I can set the result of a shell command to a variable if I do something like this:
:let wc = system('wc -w')
(so then if I issue the command :echo wc
, it displays..., ah, 0
in the info area, because I didn't give wc any text to parse.
So how do I tell the system
command which lines to pass to the external shell command it calls?
:help system()
takesinput
(though you'd probably rather usesystemlist()
). Usegetline()
orgetbufline()
to get lines from a bufferwordcount()
instead? (Not 100% sure if it will work: you'd need to set visual mode in order to apply it to your range.)