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
source to share
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
source to share