Skip to main content
Share Your Experience: Take the 2024 Developer Survey
38 votes

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

Nowdays (meaning Vim 8.1.1270) you can use: set shortmess-=S to enable a count of [x/y] showing in the bottom right corner every time you do a / or ? search. Relavant section from the Vim help Note ...
ruohola's user avatar
  • 666
15 votes

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

vim 8.1.1270 (May 2019) :set shortmess-=S Since May 2019 vim offers the possibility to show the count in the statusline (as long as it less than 99) which however is disabled by default. Add to your ...
Hotschke's user avatar
  • 4,780
10 votes

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

Thanks to this PR https://github.com/vim/vim/pull/4317 , each search command shows search statistics (like current match position, and number of matches) in vim 8.1.1270. Make sure to remove S from ...
Sven's user avatar
  • 201
7 votes
Accepted

Statusline wrong column count for multi-byte characters

Well, it looks the answer is as simple as :set statusline=%v That uses the virtual column number instead of the column number. Thanks to D. Ben Knoble for pointing me in the right direction.
Quasímodo's user avatar
  • 2,466
6 votes

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

If you use the vim-airline Plugin together with the vim-anzu Plugin, the search statistics are already displayed in the statusline. See the below screenshot (and note the [1/3])
Christian Brabandt's user avatar
6 votes
Accepted

Count number of visible lines in document with folding?

Nice idea! Here's a basic function that achieves your goal using a different technique: function! FitOnPage() normal! zR while &foldlevel > 0 if line('w0') == 1 && line('w$') ==...
Rich's user avatar
  • 32.1k
6 votes
Accepted

Count lines matching a pattern

I would like the cursor not to be moved at all during the process. You have to use winsaveview() and winrestview() functions. I believe there were similar questions answered earlier, but anyway here ...
Matt's user avatar
  • 20.8k
5 votes

vim line count of current paragraph

You can vip to select the current paragraph. If you press gCTRL + G you'll get Selected 3 of 5 Lines; 8 of 12 Words; 101 of 291 Chars; 101 of 297 Bytes
mike's user avatar
  • 949
5 votes
Accepted

Yank once then multiple paste

You can use the :put command (well :put! for P). One problem would be that the line numbers will change as you paste additional lines, so: Work in reverse order: :5 yank | 50put! | 40put! | 30put! | ...
muru's user avatar
  • 25k
4 votes

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

:redir @a | %s///n | redir END An alternative is :let @a=execute('%s///n') If %s///n is the last command, you can type: :let @a=execute('<Ctrl-r>:') or if you want to paste it immediately ...
Hotschke's user avatar
  • 4,780
3 votes

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

Apart from the native support as indicated by @Hotschke, you may want to try vim-indexed-search. This plugin also summarizes several similar plugins in its GitHub homepage.
jdhao's user avatar
  • 1,143
3 votes

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

A mapping I added to my .vimrc based on the answers here: " count nr of occurrences of word under cursor nnoremap <leader>c :%s/<c-r><c-w>//gn<cr> " count nr of occurrences ...
Emile Vrijdags's user avatar
2 votes

vim: count how many buffers been modified?

Found it. func! CountModifiedBuffer() let mod = map(getbufinfo(), 'v:val.changed') return len(filter(mod, 'v:val')) endfunc == Edit == I use %{IsBuffersModified()} instead of builtin %m ...
qeatzy's user avatar
  • 958
2 votes
Accepted

How to get the number of occurrences of a certain character on the current line in Vim?

You can count occurrences by search/replace without actual change with n option. :s,|,,gn
auditory's user avatar
  • 170
2 votes
Accepted

Can you get a count on a search where the count is > 1000 matches?

You can use the :s[ubstitute] command's n flag. As described under :h count-items: To count how often any pattern occurs in the current buffer use the substitute command and add the 'n' flag to avoid ...
B Layer's user avatar
  • 19.9k
1 vote

How to have word count exclude bracketed text?

You'll have to write a bit of custom code for this: :echo getline(1, '$')->join(' ')->substitute('\[.\{-}]', ' ', 'g')->split('')->len() getline(1, '$') gets all lines as an array, join(' ...
Martin Tournoij's user avatar
1 vote

How can I display the sloc (source lines of code)?

Note that there is an almost duplicate question: How to read/get the number of lines of code in the buffer or a directory? Now, if you want that number in the statusline... As @D. Ben Knoble said, ...
Luc Hermitte's user avatar
  • 17.4k
1 vote

vim line count of current paragraph

Sorry for not emphasize, as the tag indicates, I want a vimscript solution. Never mind, I found a solution, and wrap it in a function. func! LineCountCurrentParagraph() return line("'}") - line(...
qeatzy's user avatar
  • 958
1 vote
Accepted

Vim Word count and insert into current text

Assuming for each actor, you only have a single line with the many hyphens and your cursor is on a line with the many hyphens, you can do it like this: call append('.', "Count: ".len(split(getline('.'...
Christian Brabandt's user avatar
1 vote

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

For words use: :.,+4 s/\i\+/&/gn . denotes the current line. Also I put the following in my .vimrc file: :cabbrev zzcc s/./&/gn :cabbrev zzcw s/\i\+/&/g I can type: :.,+6 zzcw ...
user11050's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible