ChandlerQ
ChandlerQ

Reputation: 1438

How to move the cursor to the end of the tag in Sublime Text 2?

When I type the start of a tag, Sublime Text will auto-complete the end of the tag and position the cursor inside the tag.

<code>|</code>

I use | to represent the cursor. So when I finished the contents inside the tag, I want to move the cursor to the end of the tag like this:

<code>blabla</code>|

To do this, now I have to press Right button to move the cursor character by character, which is not efficient. Is there any shortcut to move the cursor to the end of the tag directly?

Upvotes: 1

Views: 2809

Answers (4)

skuroda
skuroda

Reputation: 19744

You could also create a macro. This may be valuable if your tags cover multiple lines. Save the following as something like move_to_end_tag.sublime-macro in Packages/User.

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

You can then create a keybinding for the action.

{ 
    "keys": ["ctrl+shift+alt+right"], 
    "command": "run_macro_file", 
    "args": {"file": "res://Packages/User/move_to_end_tag.sublime-macro"} 
}

Of course, you can change the keys to whatever you like.

Upvotes: 1

mackshkatz
mackshkatz

Reputation: 881

For curly braces and parentheses you can use Control + M.

Not sure about angle brackets in markup though.

Upvotes: 0

aleksblago
aleksblago

Reputation: 323

I found that annoying as well. Personally, taking the End key binding and applying it to Shift+Space works well enough for my purposes.

If that's easier for you, you can add this line to your user key bindings:

{ "keys": ["shift+space"], "command": "move_to", "args": {"to": "eol", "extend": false} }

Using a macro as skuroda suggested is a good option as well since you end up with more control of the cursor placement.

Upvotes: 0

user2340426
user2340426

Reputation: 225

I'm working in Sublime Text 3 rather than 2, but the End button (for me, between the delete and page down) does the trick for me.

Upvotes: 0

Related Questions