سؤال

In sublime I want to add a feature that if I enter a key combination. I want that combination to produce the following result:

SHIFT+Ctrl+ALT+ENTER : put a semicolon at the end of the line and create a new line and put the cursor there.

How to do it?

هل كانت مفيدة؟

المحلول

The process is quite straightforward. First, create a new file with these contents:

[
    {
        "command": "move_to",
        "args":
        {
            "to": "eol"
        }
    },
    {
        "command": "insert",
        "args":
        {
            "characters": ";\n"
        }
    }
]

and save it as Packages/User/semicolon-newline.sublime-macro where Packages is the directory opened when you select Preferences -> Browse Packages....

Next, go to Preferences -> Key Bindings-User and add the following:

{ "keys": ["ctrl+alt+shift+enter"], "command": "run_macro_file", "args": {"file": "Packages/User/semicolon-newline.sublime-macro"} }

This file is JSON-formatted, so if it doesn't have any contents when you open it, surround the line above with square brackets [ ]. If there are already entries in it, place the line above at the top (after the opening [) and add a comma , at the end, after the final closing curly brace }.

Save the keybindings file, and you should be all set. This should work with both Sublime Text 2 and 3, on any platform.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top