Sublime Forum

Move cursor past the end of closing tag

#1

Hey guys, I’m often using tab completion to create tag pairs in HTML. I want a convenient way to jump the edit cursor past the end of the closing tag >

So if I type code
I get I

The cursor’s there in the middle. I type some, then want one key to jump the cursor to beyond the closing tag’s >

It’d be ideal if this word work even when the closing tag is some distance from the cursor…

xxxxIxxxxxxxx

… so the jump would still bump the cursor over to the right of the closing tag’s >

Can this be done with a clever keybinding using a regex, or do I need to write a plugin? The inverse (ie. jump to beginning of opening tag’s <) would be useful too.

TIA

0 Likes

Shortkey to jump over closing tag?
#2

Bump. Anyone?

0 Likes

#3

There’s probably a better solution, but a macro might work.

	{
		"args":
		{
			"to": "tag"
		},
		"command": "expand_selection"
	},
	{
		"args":
		{
			"to": "tag"
		},
		"command": "expand_selection"
	},
	{
		"args":
		{
			"by": "characters",
			"forward": true
		},
		"command": "move"
	}
]

A plugin could do the same thing. Simpy call expand_selection twice, which should give you a region covering the begin and end tags. From there you can reposition the cursors at the beginning or end. Of course, a plugin would let you move to the beginning also. The above macro will only move you to the end.

0 Likes

#4

Thanks skuroda! Duplicating your macro and setting “forward” to false gets me the “back” behaviour too and I’ve bound both to a key. This is a real worker when using emmet and tag pair expansion to rapidly build HTML.

I’d like to restrict the context of my keybindings to XML/HTML. Not sure how - any thoughts?

I’m thinking there’s a more clever way to implement this entirely using keybinding regex syntax but until someone volunteers this’ll do nicely!

:smile:

0 Likes

#5

The cursor was at the end, so I thought it would just move 1 character back, rather than to the start of the tag. But whatever, it works apparently. :smiley:

Adding something like this to the context of the keybinding should restrict it

{ "key": "selector", "operator": "equal", "operand": "(text.html, text.xml)", "match_all": true }
The above is borrowed from the close_tag command in ST3 (the one that will automatically close a tag when you enter “</”).

0 Likes

#6

Nice! Thanks again :smiley:

0 Likes