I want to remove all lines in a CSS file that contain the word "color".
This would include:
body {background-color:#000;}
div {color:#fff;}
How would you do that using the :%s/ command?
I want to remove all lines in a CSS file that contain the word "color".
This would include:
body {background-color:#000;}
div {color:#fff;}
How would you do that using the :%s/ command?
And just to give you a completely different answer:
:%!grep -v color
:)
This alludes to a larger bit of functionality; you can apply your knowledge of *nix commandline filters to editing your code. Want a list of enums sorted alphabetically? Visual select, :!sort
and it's done.
You can use uniq
, tac
, etc, etc.
I'm not sure if this will work for vi, but it works in vim:
:g/color/d
See :help global
for more info.
Is that such a wise idea? You could end up doing something you don't want if your CSS has sections like this
body {background-color: #000;
font-size: large;
}
p {
color: #fff; float: left;
}
You're better off removing only the properties containing color
s/\(\w\|-\)*color\w*\s*:.\{-}\(;\|$\)//
Update:
As too_much_php pointed out, the regex I didn't exactly work. I've fixed it, but it requires vim. It isn't feasible to forge a regex that only removes problem properties in vi. Because there are no character classes, you would have to do something like replacing the \w with \(a\|b\|c\|d\|....\Z\)