Sublime Forum

How to highlight the open and close tags in sublime?

#1

Hello ;

I use notepad++ for a long time and there is an useful functions where when we click on the tag html it highlights it with the close tag :wink:

In sublime text2 I don’t know to do that ??? do you what plugin do I must install to do that ???
other question when we create our own snippets we must create it as one snippet for on file or is it possible to create :2 snippets for one file but in the code there are of course
2 tags snippets !!

thanks

0 Likes

#2

First question:
There is BracketHighlighter
github.com/facelessuser/BracketHighlighter

Not sure about the second question.

0 Likes

#3

I installed this plugin, and i didnt like that it was a long delay before the text was hilighted. any way to shorten the time from when i click to when it hilighits?

0 Likes

#4

[quote=“ludo31”]
other question when we create our own snippets we must create it as one snippet for on file or is it possible to create :2 snippets for one file but in the code there are of course
2 tags snippets !!
thanks[/quote]

If I understand correctly, what you are trying to do is to put multiple snippets in one file. I don’t think you can do this with snippets, but you can use a completions file instead.

You can find more info here --> sublimetext.info/docs/en/extensi … tions.html

And you can see an extensive example in the default HTML package (Packages > HTML > HTML.sublime-completions).

You might have to fiddle with the selectors, because snippets are given priority over completions (see the docs above).

As another example, here’s what the first part of my completions file for Markdown looks like:

{
	"scope": "meta.paragraph.markdown, text.html.markdown",
	"completions":
	
		// Headers
		{ "trigger": "h1", "contents": "# ${1:Header 1} #" },
		{ "trigger": "h2", "contents": "## ${1:Header 2} ##" },
		{ "trigger": "h3", "contents": "### ${1:Header 3} ###" }
		// and so on...
	]
}
0 Likes

#5

That was one of my dislikes with BracketHighlighter as well, when I first installed it.

If you look in the default settings file for BracketHighlighter, there is a setting called, “debounce_delay”, and the default is “500”, meaning 500 milliseconds. I changed it to “0”, and it works instantaneously. Give that a shot.

Of course, you’ll most likely want to add the changed setting to the User Settings file, instead of changing the Default Settings file.

0 Likes

#6

[quote=“tphalp”]That was one of my dislikes with BracketHighlighter as well, when I first installed it.

If you look in the default settings file for BracketHighlighter, there is a setting called, “debounce_delay”, and the default is “500”, meaning 500 milliseconds. I changed it to “0”, and it works instantaneously. Give that a shot.

Of course, you’ll most likely want to add the changed setting to the User Settings file, instead of changing the Default Settings file.[/quote]

The only downside to reducing the delay is that it may begin to cause some stalling when typing fast or quickly selecting in large files. Usually if I reduce the delay, I also reduce the search distance allowable for matching brackets/tags to cut down on lag.

It is what it is though. There are some limitations when working in Python through the ST2 API. Certain plugins and/or algorithmic approaches expose the limitations more than others (BracketHighlighter might do a little of both).

I have considered overhauling the code to do the bulk of the code on a background thread popping into the main one only to update highlighting etc, maybe taking into account waiting until typing stalls long enough. It just depends how much of the ST2 API calls are allowable on the background thread. I may have to do some serious re-architecting, but I am considering it. You will still get delays when search distance is very large though, but it would give you possibly more instant search on closer brackets/tags.

Anyways, I may fool around with this in the future when I have time and motivation. Don’t hold your breath for it any time soon though. Something like this (if it even worked well) would be a major revision.

0 Likes

#7

[quote=“quodlibet”]

[quote=“ludo31”]
other question when we create our own snippets we must create it as one snippet for on file or is it possible to create :2 snippets for one file but in the code there are of course
2 tags snippets !!
thanks[/quote]

If I understand correctly, what you are trying to do is to put multiple snippets in one file. I don’t think you can do this with snippets, but you can use a completions file instead.

You can find more info here --> sublimetext.info/docs/en/extensi … tions.html

And you can see an extensive example in the default HTML package (Packages > HTML > HTML.sublime-completions).

You might have to fiddle with the selectors, because snippets are given priority over completions (see the docs above).

As another example, here’s what the first part of my completions file for Markdown looks like:

[code]
{
“scope”: “meta.paragraph.markdown, text.html.markdown”,
“completions”:

	// Headers
	{ "trigger": "h1", "contents": "# ${1:Header 1} #" },
	{ "trigger": "h2", "contents": "## ${1:Header 2} ##" },
	{ "trigger": "h3", "contents": "### ${1:Header 3} ###" }
	// and so on...
]

}
[/code][/quote]

So if I understand I create one file sublime-completions for example for CodeIgniter and put it in folder like Codeigniter as name and it must be works??? :question:

0 Likes

#8

So I try to make like that , I create a folder CodeIgniter and I put it in packages folder !! after I create file .sublime-completions and I try to write that :

{
	"scope": "source.php - variable.other.php",

	"completions":
	
		

		{ "trigger": "email", "contents": "myadress@(${1:number})" },
		
	]
}

but it doesn’t work ??? :unamused:

0 Likes

#9

@ludo31

If that is your complete code, then you need to delete the last comma:

{ "trigger": "email", "contents": "myadress@(${1:number})" }, << delete this comma
0 Likes

#10

[quote=“agibsonsw”]@ludo31

If that is your complete code, then you need to delete the last comma:

{ "trigger": "email", "contents": "myadress@(${1:number})" }, << delete this comma

thank you so much it works :smiley:

0 Likes

#11

I have a little problem with parameter or variable which begin with $ sign

here is my example :

{ "trigger": "base_url_array", "contents": "${1:$segments} = array('${2:news}', '${3:local}', '${4:123}');
    echo base_url(${5:$segments});" },

I would like to write like that :
when I tape base_url_array

the code change like that :

$segments = array('news', 'local', '123');

echo base_url($segments);

how to do that ??? :frowning:

thanks

0 Likes

#12

Apostrophes are problematic. If you’re able to use double-quotes:

{ "trigger": "base_url_array", "contents": "\\$${1:segments} = array(\"${2:news}\", \"${3:local}\", \"${4:123}\");\necho base_url(\\$${1});$0" },
0 Likes

#13

[quote=“agibsonsw”]Apostrophes are problematic. If you’re able to use double-quotes:

{ "trigger": "base_url_array", "contents": "\\$${1:segments} = array(\"${2:news}\", \"${3:local}\", \"${4:123}\");\necho base_url(\\$${1});$0" },

thank yo so if I resume if we add $ sign we use double \ before and for the rest apostrophe and / we add \ before them ?? :wink:

0 Likes

#14

What I did, and it probably isn’t for everyone…
Default is false.

“high_visibility_enabled_by_default”: true,

It draws a box around all content associated with a certain tag. Tag to matching tag has a box. Love it.

0 Likes