Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [counting]

Questions about how to count the number of occurrences of something. Questions about the Vim feature that repeats commands should use the 'count' tag instead.

2
votes
1answer
58 views

How to yank count of matches of a pattern to a register?

%s///n show number of matching pattern like 102 matches on 102 lines. How to copy this output to a register?
3
votes
1answer
77 views

How to display in the statusline the number of matches from a search?

I've seen this question: Is there a way to count the number of occurrences of a word in a file? but most of the time I search using * or just /. It is possible to display automatically in the ...
0
votes
1answer
207 views

vim: count how many buffers been modified?

Pursuing a vimscript function or expression that count how many buffers been modified. i.e., how many buffers :bm could switch to, given that option hidden is set. == Edit == In the hope of used ...
1
vote
2answers
125 views

vim line count of current paragraph

How to count lines in current paragraph? echo line("'}") - line("'{") is near, but not correct, and not considering corner cases. How to fix? or use another approach? == Edit == I wanna count ...
7
votes
1answer
199 views

Count number of visible lines in document with folding?

I'd like to write a plugin that automatically sets the foldlevel of a newly opened document so that as much of the document fits on the screen as possible. (In other words, I'd like to make sure short ...
6
votes
0answers
81 views

Count only words for which Spell is enabled?

I want to count the words in my buffers, but for TeX files, for instance, a lot of words (e.g., commands) shouldn't be counted. I'm aware that there are scripts that do this specifically for LaTeX, ...
0
votes
1answer
128 views

Vim Word count and insert into current text

File BATMAN: -2-3-4-6-8-10-11-13-14-16-17-18-19-20-21-25-29-30-33-35-36-37-43-44-45-47-48-49-50-51-52-54-55-56-57-58-59-60-61-62-63-64-65-66-68-69-70-71-73-74-75-76-81-82-83-85-86-87-88-89-90-91-92-...
17
votes
5answers
707 views

Replace a series of asterisk bullet points with a numbered list

Imagine I have the following text: some random stuff * asdf * foo * bar some other random stuff I want to replace the asterisk bullets with numbers, like so: some random stuff 1. asdf 2. foo 3. bar ...
10
votes
3answers
1k views

How do I count the words in a part of a file, without leaving vim?

I have a file full of text (say Markdown or LaTeX). I would like to count the number of words in a part of this file. I know I can do :! wc -w % to run wc -w on the current buffer. And I know that I ...
5
votes
1answer
255 views

Count the number of whitespace in the beginning of a line

How to count the number of whitespace in the beginning of a line ( aka indentation ). eg: foo() foo() And then :command(2) 4
1
vote
0answers
50 views

How can I count instances of character “x”? [duplicate]

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, ...
9
votes
1answer
87 views

How can I easily get the length of a piece of text?

I sometimes want to check the length of a piece of text, for example in this example: str = 'Hello, world!' if len(str) == 13: print('Hello back to you!') I would like to know the length of the ...
42
votes
4answers
22k views

Is there a way to count the number of occurrences of a word in a file?

Is it possible to count how many times a word or a pattern appears in a file? This is sometimes useful to find out how many times a function has been called, etc.