Reputation: 324
I really like the way Shift + Enter is implemented in PyCharm:
Start a new line after the current one, positioning the caret in accordance with the current indentation level (equal to sequential pressing End, Enter).
I'd like to have Shift+Enter work the same way in Sublime Text 3.
I've found out there is a
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol", "extend": false} }
For "END" and
{ "keys": ["shift+enter"], "command": "insert", "args": {"characters": "\n"} },
For "Shift+enter". But I don't know how to combine them to be subsequent.
Upvotes: 2
Views: 586
Reputation: 22791
There are a couple of ways to make multiple commands execute in sequence in response to a key binding, menu entry selection, command palette input, etc.
If the commands that you're interested in running are all of type TextCommand
(which basically means they move the cursor, change the selection or edit the buffer in some fashion) then the easiest way to pull that off would be to create a macro and then bind it to a key.
For example:
Tools > Record Macro
Tools > Stop Recording Macro
and Tools > Save Macro
Each of the macro commands has an associated key binding you can use as well.
Once you're done, you will have a sublime-macro
file saved in your User
package.
Then you can bind that to a key by using the run_macro_file
command. For example:
{
"keys": ["shift+enter"],
"command": "run_macro_file",
"args": {
"file": "res://Packages/User/your_macro.sublime-macro"
}
},
As mentioned above, this only works for TextCommand
commands; commands that in some way modify the buffer directly, including the selection and cursor location. That means that you can't for example record a Find/Replace command in a macro; such commands will not be recorded in the resulting macro file.
Another method of doing the same thing is to use an extension package such as Chain of Command. This breaks the restriction of the above in that it allows you to specify any commands you want, as long as one is available. This method requires knowing the commands you want to execute, however.
In the specific case of your example, the Ctrl+Enter key already does what you want via the macro method. If you like, you could use a key binding such as the following to make it apply to the key you want:
{
"keys": ["shift+enter"],
"command": "run_macro_file",
"args": {
"file": "res://Packages/Default/Add Line.sublime-macro"
}
},
Upvotes: 1