Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM deleting/modifying HTML attributes

Tags:

html

vim

I'm new to editing html with VIM. I'm using matchit, ultisnips and surround to help me along the way.

One area which I can't seem to accomplish easily is editing attributes.

I want to go from: (cursor is |)

<input type="submit|" name="some_name" value="" id="some_name">

to:

<input type="submit" id="submit_button">

What is the fastest way to do this? Right now, I'm doing a lot of 'f' based searches.

like image 429
Thakur Avatar asked Sep 02 '11 16:09

Thakur


2 Answers

Possible solutions

wd2W

This method requires counting so maybe you would rather do wdW and just hit . until it is correct.

wd/ id<cr>

Moves to the next word so the start of name=".." the delete with d til / id. This solution can also delete across lines. You can use /... with other operators as well, e.g. c, y, and =.

Of course you can do the method you are using currently with f and just repeat with .

like image 144
Peter Rincker Avatar answered Nov 13 '22 03:11

Peter Rincker


I usually just use dW, which deletes the name, equals character and the value in parenthesis (including the parenthesis).

In some cases if I want to delete the rest of attributes to the end of the HTML tag I'm using dt/ (delete everything until you find / which is the end of input tag <input ... />)

like image 24
Jannunen Avatar answered Nov 13 '22 05:11

Jannunen