mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Count the Number of Matches as a vim til.
This commit is contained in:
@@ -62,6 +62,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
### vim
|
||||
|
||||
- [Close the Current Buffer](vim/close-the-current-buffer.md)
|
||||
- [Count the Number of Matches](vim/count-the-number-of-matches.md)
|
||||
- [Generate and Edit Rails Migration](vim/generate-and-edit-rails-migration.md)
|
||||
- [Head of File Name](vim/head-of-file-name.md)
|
||||
- [Help For Non-Normal Mode Features](vim/help-for-non-normal-mode-features.md)
|
||||
|
||||
31
vim/count-the-number-of-matches.md
Normal file
31
vim/count-the-number-of-matches.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Count the Number of Matches
|
||||
|
||||
You can use the substitution functionality in vim to count the number
|
||||
of matches for a given search term like so:
|
||||
|
||||
```
|
||||
:%s/transaction_id//n
|
||||
```
|
||||
|
||||
You will see the result in the command tray like so:
|
||||
|
||||
```
|
||||
8 matches on 8 lines
|
||||
```
|
||||
|
||||
If you want to find matches globally (that is, counting multiples per line),
|
||||
you can add the `g` flag:
|
||||
|
||||
```
|
||||
:%s/transaction_id//gn
|
||||
```
|
||||
|
||||
for a response like:
|
||||
|
||||
```
|
||||
13 matches on 8 lines
|
||||
```
|
||||
|
||||
The magic is in the `n` flag which tells vim to report a count of the
|
||||
matches and not actually perform the substitution. See `:h :s_flags` for
|
||||
more details. Also, check out `:h count-items`.
|
||||
Reference in New Issue
Block a user