Sublime text key binding only if find/replace panel is visible - sublimetext3

I've remapped the "replace_all" to to "super+enter" for making replacements, but I occasionally use this accidentally and I'd prefer to only allow this command if the find/replace panel is visible. Is there a property I can specify in the args object which provides this condition?
{ "keys": ["super+shift+enter"], "command": "replace_all", "args": {"close_panel": true} }

You can specify a context in which the keybinding operates.
For example, adding the following will ensure the keybinding will only be active when the replace panel is open and has the focus:
"context": [{"key": "panel", "operand": "replace"}, {"key": "panel_has_focus"}]
Your final key binding might look like this:
{ "keys": ["super+shift+enter"], "command": "replace_all", "args": {"close_panel": true}, "context": [{"key": "panel", "operand": "replace"}, {"key": "panel_has_focus"}] }

Related

sublime text: How to change shortcut of autopep8?

how to change the shortcut of auto pep8 in sublime text so it formats the code when i save it.
Default.sublime-keymap
[
{ "keys": ["ctrl+8"], "command": "auto_pep8", "args": {"preview": true} },
{ "keys": ["ctrl+shift+8"], "command": "auto_pep8", "args": {"preview": false} }
]
currently i have to press ctrl+shift+8 i want to change it to ctrl+s but when i try to change it doesn't change. This file is not being edited.
Select Preferences → Key Bindings, which opens a new window with the system default keybindings on the left and the user keybindings on the right. Copy the keybindings from the plugin's .sublime-keymap file into the user file on the right, then alter them as you'd like. Hit save, and they'll be activated.
In this specific case, with your wanting to assign CtrlS, which by default is the "Save" key combo, you should add a context to the keybinding so that it only runs AutoPEP8 on Python files:
{ "keys": ["ctrl+s"],
"command": "auto_pep8",
"args": {"preview": false},
"context": {"key": "selector",
"operator": "equal",
"operand": "source.python",
"match_all": true}
}

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 }]
]
}
}

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