0
votes

I'm trying to make a sublime file, either with keywords or completions or something similar to that so when I press enter, I'm moved a line down, but also I have an extra colon : at the beginning of the new line. So when I'm typing code, I can finish up the line I'm on, then press enter, and begin with a line like this :code :code [press enter] :[cursor is here]

How do I go about to making this? I have a sublime-completions file that uses "keyword" and "contents" and I want it to be similar to that, like "keys": "[enter]" and when I press enter the next line "contents" is a colon(:)?

I know there is easier ways to do this such as higlighting the text and placing the cursors at the beginning of every line but my specific situation is asking for me to have every line already finished so after I finish typing then I don't have to go back and modify anything at all.

1

1 Answers

1
votes

A key binding similar to this will do it

{
    "keys": ["enter"],
    "command": "insert", "args": {"characters": "\n: "} ,
    "context": [
        { "key": "selector", "operator": "equal", 
          "operand": "text.plain"},
    ]
}

This is a take on the default key binding for the enter key, only instead of inserting a newline only, it also inserts a ": " as well; the cursor will end up after that.

This one is set up to only function in plain text files. Most likely this is something you want to restrict only to certain file types, otherwise the enter key won't always do what you want.

You can replace the text.plain portion with an appropriate scope by pressing Ctrl+Alt+Shift+P (MacOS: Ctrl+Shift+P) while at the first character of a file of the type you're interested in.

For example, in a C file it would be source.c.