invmatt
invmatt

Reputation: 123

Sublime text find/replace remove </div>

<div class="some-class">
    Variable content here
</div>

I want to leave the content in place however the surrounding div should be removed. Obviously the opening div part is easy to get rid of but that would leave hundreds of </div>s floating around then.

Upvotes: 4

Views: 4095

Answers (3)

Husky
Husky

Reputation: 6196

The Emmet plugin has a keyboard shortcut do this, but you need to enable it in the settings.

Open the Emmet Key Bindings preferences (Preferences -> Package Settings -> Emmet -> Key Bindings) and then add this to your config file:

[
    {
        "keys": ["super+'"],
        "command": "emmet_remove_tag"
    }
]

After that you can use Cmd (Mac) / Windows key + ' to remove the tag without removing the content.

Upvotes: 1

Carl
Carl

Reputation: 11

With the Emmet plugin installed, try the following:

Select the opening div tag and press CTRL + SHIFT + " it will highlight both the opening & closing tag then you can press End followed by SHIFT + HOME and delete remove the surrounding div

Upvotes: 1

MattDMo
MattDMo

Reputation: 102862

You can do this using a regex. Select Find -> Replace, and make sure the Regular Expression button is selected. In Find What:, put

(?s)<div class="some-class">(.*?)<\/div>

and in Replace With:

$1

Example here

(?s) makes . match newline characters as well. The capture group (.*?) matches all characters in a non-greedy fashion, so that the group ends at the first </div>. Otherwise, it would match all the way up to the last </div> (example). The replace value $1 is the first (and in this case only) matching group.

Upvotes: 5

Related Questions