Sublime Forum

Update closing HTML tag after changing the opening tag

#1

I’ve recently purchased a Sublime License (ST4) for personal use after testing out the editor for a few weeks. (I run a fansite for a niche pet raising sim franchise and was looking for alternatives to BlueFish HTML editor which has been unstable for me and Sublime was the only editor I could find that handled my use case scenarios).

When I was testing, I was certain that there was a feature that automatically changed a closing HTML tag after changing the opening tag

Example: Starts out as “<h4>sometext</h4>”… Edit <h4> to <h2> and the closing tag automatically changed to </h2>.

I know that the SHIFT+ALT+W inserts tags already selected where both change if you type something, but…
did I imaging the other scenario?
Not having a GUI toolbar and such has been a learning curve in ST and I’ve been making a list of Hotkeys to keep up alongside ST until they become muscle memory, but I worry I hit an accidental keybind that might have turned off the other feature (assuming i didn’t imagine it).

For the short term, I’ve use a workaround for this by finding the BracketHighlighter package, and setting a hotkey to “Select Tag Name” (open and close), so now I can select both and edit at once. I can learn to use this going forward, but just wanted to make sure I didn’t dream up what I thought was built in… or possibly un-set something.

Installed Packages:

  • BracketHighlighter
  • Emmet
  • Package Control
  • SideBarEnhancements
0 Likes

#2

You can use the Emmet Rename Tag command for this (I have mine mapped to CMD+Shift+K).

Place your cursor anywhere within the tag or it’s contents, then invoke the command. This will select both the opening and closing tag, so you can type over them with the new tag.

0 Likes

#3

Thanks for the tip. I’ve tried to use this manually (I haven’t mapped it to a keybind yet, just searching for the command and selecting it) but it doesn’t seem to do anything. I’ve tried selecting inside the tag, highlighting the tag first, then attempt to change the tag but nothing happens either way.

What is the expected behaviour? Is it a possible conflict with bracket highlighter?

Either way, the BracketHighlighter method does work which seems like it might be what you are describing with Emmet which means that likely it was never baked into vanilla ST.
I must have imagined the auto-update scenario, or used some other feature/keybind without understanding what it was yet so I may just be remembering it wrong.

0 Likes

#4

Hi Fenrick. This short screen video shows Emmet Rename Tag in action. I also have bracket highlighter so don’t believe there is a conflict.

0 Likes

#5

Thank you! after seeing this, I must have been selecting the wrong command by accident or some other user error.
EDIT: The error was on a non-standard HTML that had simple HTML that is PHP included into other pages. When testing on any other page properly made, the function seems to work as expected.

I was able to reproduce with Emmet’s Rename Tag as you’ve demonstrated perfectly.

I made an absolutely wild guess for the command name:

   {
        "keys": ["ctrl+alt+m"],
        "command": "emmet_rename_tag"
    }

And this worked and functions what seems to be identical to the BracketHighlighter option.
sublime_text_sudwvi4kll
Is there a reference for Emmet (or any packages for that matter) to know what these actions are called without guessing while assigning keybinds to these actions?
Or do all of them follow this example of packagename_command_name

0 Likes

#6

If you launch the Command palette then search for Emmet, you will see all the commands and keybindings.

More generally, if you look to the package settings for any package, you can see (and customise) any keybindings associated with that plugin (assuming the plugin author has factored this into their design)

0 Likes

#7
  1. The first screenshot I have become familiar with (Command pallet and looking for commands and such. This was very awkward at first transitioning from a toolbar style editor, but after a few days of getting used to it… yeah I’ve really come to like it)

  2. That second screenshot… I feel very silly and a bit embarrassed that I did not realize at first glance that these keybinds are “set” but just commented out. I had simply written in what I thought might be the command on the right panel (User settings as opposed to directly editing default IIRC?)

Thank you haha.
I am humbled by my ignorance, but glad things are making more sense as I spend more time with the editor! Thank you again for the patience and responses :slight_smile:

0 Likes