Let's say I have the following bit of code:
v = [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0]
I want to know how many elements are in v.
My current solution, if v
isn't too large, requires a bit of counting, but it makes for more readable code:
v = [0,0,0,0,
0,1,0,0,
0,0,0,0,
0,0,0,0]
This is less helpful when v
is large.
It also occurs to me that I could just pipe the line into the shell (assume it's line 1)
:1 ! tr -dc ',' | wc -c
But this replaces the contents of line 1 with 15 (which is the answer I am looking for ... nothing undo cannot fix)
Is there a better vim command to count how many times a character appears in a selection/line/range?