Home Download Buy Blog Forum Support

Move cursor past the end of closing tag

Move cursor past the end of closing tag

Postby qgates on Mon Jun 03, 2013 1:39 am

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 <tab>
I get <code>I</code>

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...

<code>xxxxIxxxxxxxx</code>

... 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
qgates
 
Posts: 225
Joined: Mon Nov 05, 2012 4:33 pm

Re: Move cursor past the end of closing tag

Postby qgates on Wed Jun 05, 2013 1:55 pm

Bump. Anyone?
qgates
 
Posts: 225
Joined: Mon Nov 05, 2012 4:33 pm

Re: Move cursor past the end of closing tag

Postby skuroda on Wed Jun 05, 2013 6:35 pm

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

Code: Select all
[
   {
      "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.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Move cursor past the end of closing tag

Postby qgates on Wed Jun 05, 2013 10:50 pm

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!

:)
qgates
 
Posts: 225
Joined: Mon Nov 05, 2012 4:33 pm

Re: Move cursor past the end of closing tag

Postby skuroda on Wed Jun 05, 2013 11:10 pm

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. :D

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

Code: Select all
{ "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 "</").
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Move cursor past the end of closing tag

Postby qgates on Wed Jun 05, 2013 11:28 pm

Nice! Thanks again :D
qgates
 
Posts: 225
Joined: Mon Nov 05, 2012 4:33 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 32 guests