I'm editing an HTML file, and my cursor is inside a tag, like this:

<textarea class="code-area"></textarea>

And I'm trying to wrap all of this tag inside a div tag, so that it'd be like this:

    <textarea class="code-area"></textarea>

I can use vim-surround and type yss<div>, but it'll change it into this:

  <div><textarea id="code-area"></textarea></div>

How can I wrap it so that it adds newlines as well?

Also, the yss<div> command only wraps the current line. I'm interested in wrapping an entire tag, no matter how many lines it has.

  • 2
    Does ySat<div> fit? – Matt Dec 24 '19 at 7:49
  • @Matt Yes, it does. Thank you. – Amir A. Shabani Dec 24 '19 at 7:52

In vim-surround ys{motion} puts "a surround text" on the same line. To place it on a line of its own with indent you should use yS{motion} instead.

Next, a motion you want for this case is :h at (a tag). So this results in ySat<div>

| improve this answer | |

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.