Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get vim to display number of commas in one line

Tags:

vim

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.

like image 393
PyariBilli Avatar asked May 25 '13 08:05

PyariBilli


People also ask

How do you count the number of lines in a comma?

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.

How do you count characters in Gvim?

For counting the number of words, press g, then Ctrl+g. This will display the number of words currently in the buffer.

How many characters are in vi?

> Do these restrictions hold for Vi, as well? 128 characters per global command-list. 1024 characters per filename.

How to remove char in Vim?

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.


2 Answers

Just make a search and count matches :

:s/,//gn
like image 53
deufeufeu Avatar answered Oct 06 '22 17:10

deufeufeu


: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.

like image 8
romainl Avatar answered Oct 06 '22 18:10

romainl