sublime text: How to change shortcut of autopep8? - sublimetext3

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

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 change the auto-complete select key in Sublime Text 3?

I have used vim for a while, in vim auto-complete, I use 'tab' 'down' to select the next candidate, 'shift+tab' 'up' to select the previous candidate, 'enter' to confirm that completion.
But in Sublime Text 3, I found 'tab' and 'enter' are both to confirm completion, only 'up' 'down' is to select the previous/next candidate.
How can I set the key like vim auto-complete mode ?
Just add this to your keymap:
{
"keys": ["tab"],
"command": "move",
"args": {"by": "lines", "forward": true},
"context": [{"key": "auto_complete_visible"}]
},
{
"keys": ["shift+tab"],
"command": "move",
"args": {"by": "lines", "forward": false},
"context": [{"key": "auto_complete_visible"}]
},
The context auto_complete_visible enables the keybinding only if the autocomplete popup is visible.

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

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

Emmet plugin's expansion doesn't work for Sublime Text 3

I successfully installed Emmet via Package Control.
When I type ul and press Tab, I get <ul></ul>.
When I type ul.class and press Tab, I get ul.body_class but I want it to generate <ul class="class"></ul>.
What am I doing wrong?
I have read posts saying to try Ctl+E instead of Tab as the trigger key, but that doesn't do anything.
Try using Ctrl+Space instead. If that doesn't work, you can try changing the keybinding by putting the following in your User key bindings file which can be found by doing Preferences -> Key Bindings — User:
[
{"keys": ["tab"], "args": {"action": "expand_abbreviation"}, "command": "run_emmet_action", "context": [{"key": "emmet_action_enabled.expand_abbreviation"}]}
]
and then just change "tab" to whatever keybinding you want. Check to see if that works.
After reading your question, I installed Emmet in the Windows version of Sublime Text 3 today and had the same problem. Within my search for the solution, I found the following:
http://docs.emmet.io/actions/expand-abbreviation/#comment-1272517661
In Windows I opened the Default Emmet Preferences. By going to:
Preferences > Package Settings > Emmet > Setting - Default
and
Preferences > Package Settings > Emmet > Key Bindings - Default
As I was closing the settings files, I was prompted to save the setting files. I clicked OK to save and then restarted Sublime Text 3.
After Sublime Text 3 reloaded:
I created a new html file and was able to type ul.class, tabbed and it expanded to <ul class></ul>
It was funny, I never ran into that problem with Sublime on my Mac. If you had to do the same process on Mac, you go to Preferences > Package Settings > Emmet ...
I was facing same issue. Just pasted the below code in "Preferences -> Key Bindings — User:".
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
"operand": "SCOPE_SELECTOR",
"operator": "equal",
"match_all": true,
"key": "selector"
},
// run only if there's no selected text
{
"match_all": true,
"key": "selection_empty"
},
// don't work if there are active tabstops
{
"operator": "equal",
"operand": false,
"match_all": true,
"key": "has_next_field"
},
// don't work if completion popup is visible and you
// want to insert completion with Tab. If you want to
// expand Emmet with Tab even if popup is visible --
// remove this section
{
"operand": false,
"operator": "equal",
"match_all": true,
"key": "auto_complete_visible"
},
{
"match_all": true,
"key": "is_abbreviation"
}
]
}
Github: See for more description
I check the emmet default key is ctrl+e, so I add this to my Key Bindings - User:
{"keys": ["tab"], "args": {"action": "expand_abbreviation"}, "command": "run_emmet_action", "context": [{"key": "emmet_action_enabled.expand_abbreviation"}]}
I will have shared this as a comment directly where I feel like but 50 reps was required. Any ways. Here is what I did that made mine work for me.
From #saadq's answer, do this:
[
//other user key bindings should be here, followed by
{"keys": ["tab"], "args": {"action": "expand_abbreviation"}, "command": "run_emmet_action", "context": [{"key": "emmet_action_enabled.expand_abbreviation"}]}
]
The point is to have other bindings appear before it so that whatever binding overwriting it will be overwritten again.

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