When editing the contents of an HTML tag or changing the tag type in Vim, there are several useful shortcuts and techniques you can use:
-
Inside Tag Editing:
- To edit the contents within the current HTML tag, place your cursor inside the tag and press
ci>
(change inside>
). This will change everything within the tag, but leave the tag itself intact.
- To edit the contents within the current HTML tag, place your cursor inside the tag and press
-
Changing the Tag Type:
- To change the HTML tag itself, place your cursor on the tag you want to change, and use the following commands:
- To change a
<div>
to a<span>
, for example, you can usecit
(change inside tag) and type<span>
. - If you want to change a
<div>
to a<p>
, you can usecit
and type<p>
. - To change a
<span>
to a<div>
, you can usecit
and type<div>
.
- To change a
- To change the HTML tag itself, place your cursor on the tag you want to change, and use the following commands:
-
Tag Surroundings:
- If you want to surround an element with a new tag, you can use the
surround.vim
plugin, which allows you to visually select text and then specify a new tag to surround it. For example, you can select a block of text, pressS
, and then type the new tag you want to wrap around it.
- If you want to surround an element with a new tag, you can use the
-
HTML Commenting:
- To comment out an HTML tag or a block of code, you can use the following shortcuts:
gcc
to comment a single line.:x,ys/old/new/g
to replaceold
withnew
in linesx
throughy
(e.g.,:1,5s/<div>/<p>/g
to replace<div>
with<p>
in lines 1 through 5).
- To comment out an HTML tag or a block of code, you can use the following shortcuts:
-
Changing Case:
- To change the case of an HTML tag (e.g., from lowercase to uppercase), you can visually select the tag and use the
~
key to toggle the case.
- To change the case of an HTML tag (e.g., from lowercase to uppercase), you can visually select the tag and use the
-
Auto-pairing Plugins:
- Consider using Vim plugins like
auto-pairs
orsurround.vim
, which can assist in auto-closing and modifying HTML tags.
- Consider using Vim plugins like
No comments:
Post a Comment