Sublime Forum

How to edit both opening and closing tag simultaneously

#1

In the screenshot below, how can I quickly change the a to button? I.e. how do I edit both the opening and closing tag name? Sometimes I can use ctrl+d, but, especially with <a> tags, that of course breaks down pretty quickly whenever the name is somewhere between the opening and closing tags.

As you can see in the screenshot below, the highlighter does seem to know where the opening and closing tags are at least, so is there a way to “get to them”? Basically to get what’s underlined there selected so I can edit them both?

So, in this specific case, get a selection of the a in both the opening and the closing tag?

Screenshot

1 Like

Auto treat CDATA tags like comments
#2

Do you mean if you have one <a> tag nested inside another? In your example above, this works with Ctrl+D just fine; you just want to make sure that you put the cursor on the a and press the key, don’t select the a first (otherwise Sublime will infer you want to select all of the a characters).

Apart from that, I don’t think there’s a built in command for selecting the pair of the tag, but a package could provide such a thing. The only one that I’m aware of off the top of my head that does this is the Emmet package, but that’s not something that I would recommend using in the general case because it seems to cause more problems than it’s trying to solve.

3 Likes

#3

https://packagecontrol.io/packages/xpath can do it, but it is mainly designed for well formed XML, so it may not work for HTML tag soup

1 Like

#4

Ah! That helps! Pressing ctrl+d twice without the a selected first actually does work. :+1::+1:

Just tested nesting <a> tags inside each other, and then, yeah, it does go through all of them, but that doesn’t really happen that often. My main issue was how to avoid selecting the a in class and so forth, like it does when you manually select the a first, as you mention.

So, thank you! :blush:

And yeah, I looked at that Emmet package a while ago, and it seems like… a lot:flushed:

2 Likes

#5

From reading about it, it does seem very XML focused, yeah (naturally, as it should be). I’m doing not only HTML, but also JSX and typescript and such, so stuff isn’t exactly pure well formatted XML. :stuck_out_tongue:

Thanks for the tip though! Might be useful if I need to do a lot of XML stuff again (which I had to some years ago). :slightly_smiling_face::+1:

0 Likes

#6

In the case of a nested link, you can use Ctrl+KCtrl+D when one of the inner tags is selected to unselect it and skip to the next item instead. If there are only a few, that’s pretty quick to do, though if there are a lot of extras to skip it’s generally easier to just make such selections manually.

1 Like

#7

Right, but that would require me to learn that K D shortcut, which my brain seem unwilling to learn for some reason, haha. :stuck_out_tongue:

But yeah, that’s a good tip. And now I have yet another place to find that shortcut too. Thanks!

0 Likes