bashkovpd
bashkovpd

Reputation: 598

Remove lines around pattern in Vim

There is a css file and I want to make two things:

1) Remove all webkit keyframes and surrounding whitespace characters like:

@keyframes outToLeft {
    to {
        opacity: 0;
        -webkit-transform: translate3d(-100%, 0, 0);
        transform: translate3d(-100%, 0, 0);
    }
}

2) Remove all webkit prefixed properties and surrounding whitespace characters like:

-webkit-transform: translate3d(100%, 0, 0);

I tries to use %s but it doesn't work (maybe my construction wasn't right)

What is the best way to do this?

Upvotes: 1

Views: 409

Answers (2)

Antón R. Yuste
Antón R. Yuste

Reputation: 1010

It isn't possible, IdeaVim doesn't support the global g: command.

See https://youtrack.jetbrains.com/issue/VIM-831 for more information and updated status.

If replace it with empty line is fine, you could do something like :%s/.*-webkit.*//g

Upvotes: 1

B.G.
B.G.

Reputation: 6026

The solution is the global :g command.

For your first part, it would look like this:

:g/@^keyframes/norm d}

which means on every line matching the pattern ^@keyframes do norm d} norm allows to give the block a normal command. d} deletes the whole block.

for the second example it is even easier, we can use the :g command with the d flag:

:g/^-webkit/d

d just means delete.

Since you mentioned whitespaces maybe the lines should look like that:

:g/@^keyframes/norm d}dk

to delete the line before and after the block, or to keep one line:

:g/@^keyframes/norm d}dd

the same goes for the second example:

:g/^-webkit/norm dj

if you want to delete the following line too.

Upvotes: 1

Related Questions