I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to count the occurrence of a specific word or line in a file. I was trying to do this with a filter, using the following command:
:g/http/w !wc -l
However, this ran w !wc -l
for every line matching the file, so I got the total number of lines in the file, a number of times equal to the number of matches.
What I was expecting, was something akin to this line:
:%!grep http | wc -l
Is something like this possible in vim using filters or commands? If not, I'm fine using the grep wc solution, but it would be nice having a clean way to do this from vim.
I've also noticed that :g/http/p
prints all the matching lines, but I don't have the option of piping the output to an external command using the print command. Is there anything else I could use?