SamuraiJack
SamuraiJack

Reputation: 5549

Visual Studio Code: How to remove html tags and write to multiple lines at the same time?

How does one do this:

This what I want to achieve

I found many useful tricks here Multiline editing in VSCode

I know I could use Ctrl+Alt+Shift+Up/Down I know I could just press Shift+Up/Down to and delete the opening li tags together. But the closing li tags are not in the same line of sight.

How does one do what is being shown in the above example.

Upvotes: 3

Views: 9077

Answers (3)

Johan Faerch
Johan Faerch

Reputation: 1206

You have the entire keyboard shortcut overview directly in VSC Ctrl + K or Ctrl + R or Help menu 'Keyboard Shortcuts Reference'

  1. Mark your desired characters.
  2. Hit Ctrl + F2 to mark all similar occurrences.
  3. Change everything simultaneously.
  4. Repeat for additional changes.

Upvotes: 1

Mark
Mark

Reputation: 182641

There is an emmet command that will remove a tag for you: editor.emmet.action.removeTag. It is currently unbound to any keybinding but you could easily make your own. Here is a demo without binding that command:

  1. Select your <li>'s however you choose [I use Ctrl-Shift-L in the demo - but that selects all of them in the file which may or may not be appropriate for your use case.]
  2. Trigger the editor.emmet.action.removeTag
  3. Arrow over to your insertion points.

Pretty easy especially if you give that emmet command a keybinding.

emmet remove tag description

Upvotes: 2

SamuraiJack
SamuraiJack

Reputation: 5549

Alright, combining valuable comments by @Nick and @Strelok (thanks guys), Here is the answer:

Step 1: Select <li> using Shift+Right

Step 2: Press Ctrl+D several times till all the <li> tags are selected.

Step 3: Press Del

Step 4: Press End

Step 5: Press Backspace to delete closing </li> tags

Step 6: Press Home

Step 7: Press Left key till you are at the right spot inside <a> tag. And then type whatever you wish to.

Even though I could deduce this answer only from the comments by @Nick and @Strelok, I decided to post the answer myself because it would be unfair to mark one as answer when both the comments were equally helpful. I am going to keep the question open for now just in case someone comes up with a better way. Perhaps a way to avoid pressing Ctrl+D multiple times.

Upvotes: 3

Related Questions