I have a long line with many commas. I would like to know the number of commas in a line. How can i do this using vim?
Also, I want to do this for characters other than comma.
Specifying the line number and a character should give me the number of occurrences of that character.
for example :
:charmap/50/,
should give me the number of commas in line 50.
Select the cell you will place the counting result, type the formula =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) (A2 is the cell where you will count the commas) into it, and then drag this cell's AutoFill Handle to the range as you need.
For counting the number of words, press g, then Ctrl+g. This will display the number of words currently in the buffer.
> Do these restrictions hold for Vi, as well? 128 characters per global command-list. 1024 characters per filename.
To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.
Just make a search and count matches :
:s/,//gn
:s/,//gn
reports the number of ,
on the current line without doing the substitution
:50s/,//gn
does the same for line 50.
See :h s_flags
for /n
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With