How to move the cursor to the end of the tag in Su

2019-08-05 10:19发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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

Not sure about angle brackets in markup though.