Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut or yank an entire tag in VIM

Tags:

html

vim

frontend

Given a common html bit like

<div>
  <p>
    Mary had a <b>little</b> lamb.
  </p>
</div>

I want to cut the entire (not the inner only) div for pasting elsewhere. I know there are alternative ways to do this like cutting a range of lines etc., but as a newish user of VIM I sorely need to move around tags in my frontend workflow and I just haven't seen a great way to do this yet.

like image 697
iamnotsam Avatar asked May 16 '14 15:05

iamnotsam


People also ask

How do I delete a tag in Vim?

press d ("d") to delete it.

How do I yank a block in vim?

You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before).

What is +Y Vim?

if you yank with "+y , you actually yank to and subsequently paste from what's called the "clipboard". In that case you will clobber whatever was in the clipboard up to that instant. To paste outside vi/vim, just use the usual CTRL + v `.


1 Answers

With your cusor on the outer div tag: dat

d elete a round t ag

Then paste it with p where you need it.

like image 195
Tom Cammann Avatar answered Oct 20 '22 15:10

Tom Cammann