Sublime Text 3: Switching 'ctrl+enter' and 'enter' - sublimetext3

I realized I use 'ctrl+enter' a lot more than 'enter' in ST3. Would it be possible to switch these two commands?
I can easily switch 'ctrl+enter' to 'enter' with:
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line.sublime-macro"} }
But I'm not sure how to switch 'enter' to 'ctrl+enter'. It seems that only the "auto-completion" functionality of 'enter' is defined in the default keymap.
{ "keys": ["enter"], "command": "commit_completion", "context":
[
{ "key": "auto_complete_visible" },
{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
]
},
Any thoughts would be much appreciated!
PS. And if there was a way I could keep 'enter' to commit completion while also using it to skip to next line, that would be the icing on the cake.

Nevermind, I found it:
{ "keys": ["ctrl+enter"], "command": "insert", "args": {"characters": "\n"} },
That just leaves the question of how to continue to use 'enter' for auto-completion. If anyone has any ideas, I'd be curious to hear them!

Related

Is it possible to use C-x C-s for saving in Sublime Text 3

In Sublime Text 3 is it possible to use C-x C-s for saving the file (save_all), while keeping C-s for search option?
ctrl+x+s or ctrl+xctrl+s did not work on my end.
{ "keys": ["ctrl+s"], "command": "find_next", "context":
[{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
{ "keys": ["ctrl+x"], "command": "noop" },
{ "keys": ["ctrl+x+s"], "command": "save_all" },
{ "keys": ["ctrl+x+ctrl+s"], "command": "save_all" }
Binding key chords like this in Sublime requires you to specify both keys individually in the keys list (that's why it's a list).
So, what you want is:
{ "keys": ["ctrl+s"], "command": "find_next", "context":
[{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
{ "keys": ["ctrl+x"], "command": "noop" },
{ "keys": ["ctrl+x", "ctrl+s"], "command": "save_all" },
Note that the binding of Ctrl+x to noop is not needed for this to work, so you can leave that out. However using the same key for both single items and in chords like this may require you to hit the key twice to get Sublime to trigger the command, since it otherwise can't tell without some delay which of the bindings you intended.

How to make Sublime Text 3 to move the cursor to the next line after ctrl + / comment?

I want to comment out pieces of code with one-line comments without using the arrows, like I do in IDEA, but Sublime Text 3 stays on the same line after commenting. How can I change this behavior?
The simplest solution is to use a Macro for this that combines together the commands for toggling a line comment and then moving the cursor, and then rebinding the key to run the macro.
Such a macro would look something like the following. Here this is saved as Packages\User\comment_line.sublime-macro.
[
{
"command": "toggle_comment",
"args": {"block": false }
},
{
"command": "move",
"args": {"by": "lines", "forward": true }
}
]
With this in place, you can add a binding such as the following to your custom key bindings:
{
"keys": ["ctrl+/"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/comment_line.sublime-macro"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": "true", "match_all": true },
]
},
If you change the name of the macro when you save it, that needs to be reflected here.
This binding includes a context that makes it only apply when there is no selection, in which case this binding will be ignored and Sublime will use the default instead.
That can be removed if you wish. However, WebStorm (the only JetBrains tool I have handy at the moment) operates in this fashion, so presuming that IntelliJ does as well this more accurately mimics what happens there.
Additionally, if you're mapping a different key to the comment command, make sure the original line is above the new addition:
{ "keys": ["ctrl+q"], "command": "toggle_comment", "args": { "block": false } },
{
"keys": ["ctrl+q"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/comment_line.sublime-macro"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": "true", "match_all": true },
]
},
There's a plugin called "Chain of Command" which can be found in here: https://github.com/jisaacks/ChainOfCommand
Once you have it installed, you can simply add the following to your key bindings:
{
"keys": ["super+forward_slash"],
"command": "chain",
"args": {
"commands": [
["toggle_comment", { "block": false }],
["move", { "by": "lines", "forward": true }]
]
}
}

Implement Vim-like imap mapping in sublime-text 3

I would like to have ; inserted at the end of line, when I press ;; while in insert mode. What would be mapping for that in sublime-text 3?
Somtehing like:
inoremap ;; <C-o>A;
in VIM.
So far, I managed to get to EOL I am currently on, but have no idea on how to chain other command to insert ;. I was not able to find anything in documentation on running multiple commands in sequence.
{
"keys": [";", ";"],
"command": "move_to", "args": { "to": "eol" }
}
As I wasn't able to find any native-to-editor solution to this,
luckily there is a plugin called Chain of Command
https://packagecontrol.io/packages/Chain%20of%20Command
Then you can put this into user keymap settings file:
{
"keys": [";", ";"],
"command": "chain",
"args": {
"commands": [
[ "move_to", { "to": "eol" }],
[ "insert", { "characters": ";" } ]
]
},
// with a help of this line, command won't get executed
// if in command_mode (vintage mode enabled), so it applies to insert mode
// only.
"context": [ { "key": "setting.command_mode", "operand": false } ]
}

How to switch to command mode after press "Save" hotkey in Sublime Text 3?

SUBJ.
I recently switched to Sublime from vim and trying to configure Sublime Text 3 in the way which I used to.
If I add binding, like below:
{ "keys": ["super+s"], "command": "exit_insert_mode", "context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
it switches mode to command, but do not save changes.
What you have specified overrides the existing save key binding, so it is behaving as expected. You will need to use a plugin or a macro to get the behavior you want. A macro would require you to save an additional file, so that's up to you. For a plugin solution, you should be able to use https://github.com/skuroda/ImprovedMacros to get the behavior you want. Replaying commands is based on some work I found on the ST forums. Never got around to finding a good way to record actions better though. That aside, there are install instructions in the README. I believe the following will work as your key binding with the plugin installed
{
"keys": ["super+s"], "command": "run_multiple_commands",
"args": {
"commands": [{
"context": "view",
"command": "save"
},{
"context": "view",
"command": "exit_insert_mode"
}]
},
"context": [
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}

How do I remap escape when in Sublime Text vintage mode?

I am a vim user who is moving to Sublime text and using Vintage mode. In my .vimrc I have the following line:
imap jk <Esc>
In vim, this allows me to escape out of insert mode without having to lunge for the escape key and keep my fingers on the home row. How do I do the same thing with Sublime Text Vintage mode?
"Vintage mode is implemented entirely via key bindings and the plugin API - feel free to browse through the Vintage package and see how it's put together. As an example, if you'd like to bind "jj" to exit insert mode, you can add this key binding:"
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
Just modify first line to jk if you prefer that.
Source
If you are using the Vintageous plugin, use the following key binding:
{
"keys": ["j", "k"],
"command": "_enter_normal_mode",
"args": {"mode": "mode_insert"},
"context": [{"key": "vi_insert_mode_aware"}]
}
Also, Ctrl+[ works and is much easier to reach for than the esc key. This is in OSX at least.
For anyone using Neovintageous 1.22.0, you can set these options in Sublime Text preferences to remap <Esc>:
"vintageous_i_escape_jj": true
"vintageous_i_escape_jk": true
And that's it.
You don't need to add keys configuration into preference > settings but you need to add it into preferences > keybindings. Add the following code below:
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
Save the file. Test it, it should work.
https://www.sublimetext.com/docs/vintage.html#included

Resources