0

I have a code like this:


h5 style=("text-align: center; margin-top: 2rem;") some text
p style=("text-align: center; margin-top: 2rem;") some text

And in first line, I want to delete margin-top: 2rem;, so the result will look like this:

h5 style=("text-align: center;") some text
p style=("text-align: center; margin-top: 2rem;") some text

Currently I am using x to delete or dw to delete each text but it seems not a good idea, do you have any suggestion?

2

There's indeed more straight-forward ways to do this.

As you can see in the help for :h d

                            *d*
["x]d{motion}       Delete text that {motion} moves over [into register
            x].  See below for exceptions.

The delete command, as many, accepts a motion. This means you can tell Vim what object you want to delete (diw for "delete inner word", dap for "delete around paragraph...).

In your case, dt; seems to be appropriate: it will delete from the cursor position until (not including) the next ;.

df; will do the same, but including the ;.

3

You can use the f or t motions for this. With your cursor at the start of the text you want to delete:

 h5 style=("text-align: center; margin-top: 2rem;") some text
                               ^

Type either of these:

df;
dt"

The first deletes up to and including the ; character, the second deletes up to but not including the ".

See :help 03.3 for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.