Vim count number of lines not containing pattern

Given the CSV file below, how can I use vim to count the number of lines that do not contain: fff

orsss

aaa bbb ccc ddd eee, 3221
aaa ddd eee fff, 3222
fff ddd sss www aaa, 3223
ggg www qqq, 3224
sss aaa vvv, 3225

      

I have this, but it only matches some and not all

%s/\v^(fff|sss)//gn

      

+3


source to share


2 answers


The anchors are ^

at the beginning of the line, so it matches lines starting with fff or sss . It's kind of a negative result only if inside the square brackets ( [^a]

matches anything other than a

).

You are looking for something like this:

%s/\v^((fff|sss)@!.)*$//gn

      

More information at :help @!

.

Another solution that avoids the complex regex is to use a global command to increment the variable on all lines that do NOT match the pattern:



let var=0
v/\v(sss|fff)/let var+=1
echo var

      

Edit:


You can delete all lines using the following global command:

g/\v(sss|fff)/d

      

+3


source


You can invoke command line permissions from vim with%. Enter the following command and press enter. This will give you the look and feel to give you the answer. Click again and you will be returned to vim just like before.



:%!grep -c -v -P "fff|sss"

      

+2


source







All Articles