Monday, October 23, 2023

vim html editing

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:

  1. 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.
  2. 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 use cit (change inside tag) and type <span>.
      • If you want to change a <div> to a <p>, you can use cit and type <p>.
      • To change a <span> to a <div>, you can use cit and type <div>.
  3. 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, press S, and then type the new tag you want to wrap around it.
  4. 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 replace old with new in lines x through y (e.g., :1,5s/<div>/<p>/g to replace <div> with <p> in lines 1 through 5).
  5. 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.
  6. Auto-pairing Plugins:

    • Consider using Vim plugins like auto-pairs or surround.vim, which can assist in auto-closing and modifying HTML tags.

No comments:

Post a Comment