I want to find the number of times 'x' is present in my file, so I submit %s/x//gn
and get the correct answer.
How can I capture the resultant count into a variable using vimscript on the command-line?
The following solution was hinted at by an answer below:
:let cnt=0
:g/x/let cnt=cnt+1
:echo cnt
However, cnt
is made to store the total number of lines in the buffer that have an x
, not how many x
s there are in the whole file.
So, the original question still stands.