Matthew Jewell 4 years ago • updated by Tom Fagerland 5 months ago 4
Ie. when typing php function $this->method('asd the ') are automatically created, meaning that you have to go to the end of the line, add the semi colon then press return.

Maybe could be bound to alt+;?

Might be possible to do already, but i haven't looked into expanding sublime text yet.
This can be done with a macro. Take a look in Preferences > Key Bindings - Default and search for "Add Line.sublime-macro" – you can modify this to insert a ";" before the "\n".

Then put the new macro into Packages/User and update Preferences > Key Bindings - User with your key bind.

Thanks for reminding me how useful that shortcut is in TextMate. Here's how to do the same in Sublime Text. Define a macro with this content and save it as Packages/User/Line terminator and newline.sublime-macro:
    { "command": "move_to", "args": {"to": "eol"} },
    { "command": "insert_snippet", "args": {"contents": "${TM_LINE_TERMINATOR:;}\n"} }
And a key binding, perhaps this one (the same as in TextMate)
    "keys": ["alt+super+enter"],
    "command": "run_macro_file",
    "args": {"file": "Packages/User/Line terminator and newline.sublime-macro"}
I haven't checked if any of the language definitions in Sublime text actually defines TM_LINE_TERMINATOR, but if they do the macro will use it. If not it defaults to ; which works in many languages.
Thanks for this. Here's a version that inserts a semicolon at the end of the line without moving the cursor:

    { "command": "set_mark" },
    { "command": "move_to", "args": {"to": "eol"} },
    { "command": "insert_snippet", "args": {"contents": "${TM_LINE_TERMINATOR:;}"} },
    { "command": "swap_with_mark" }
Quick additional question: How can I specify this macro to only work in specific syntaxes. Javascript and Java, for example, but not Python.
Obviously adding it separately to both JS and Java.