Sublime text shortcut to open keybindings and settings - sublimetext3

I would like to be able to map a keyboard shortcut to be able to open the settings and open the keybindings.
I would like it to behave the exact same as going to Menu > Preference > Settings \ Keybindings.
Is this possible?

If a command appears in a Menu or in the command palette, then it's possible to bind it to a key provided you can determine what the command is and what arguments it takes.
One way to determine that for a menu item is to use View Package File from the command palette and then open the appropriate menu resource. The main menu always comes from a Main.sublime-menu resource, so once you enter the command you can enter Main.sublime-menu in order to see all of the resources that match, then pick the one for the appropriate package.
For a command that appears in the command palette you can do the same by entering sublime-commands to see all of the files that are contributing commands to the command palette and then select the appropriate one to see what command it's executing.
For determining the command bound to a key (in case you want to go the other way and add it to a menu or the command palette) you would look for sublime-keymap files instead.
These options require you to either know the package that is contributing the command or be able to infer it based on what it does. The Default package is what contains the default Sublime behaviour; other files augment the files from that package.
Another method is to open the Sublime console with Ctrl+` or the menu item View > Show Console and then enter the command sublime.log_commands(True) to turn on command logging.
With that enabled you can take the action you want to know the command for and the console will tell you the command being executed and what arguments it's taking.
In your particular case, the output in the console would be:
command: edit_settings {"base_file": "${packages}/Default/Default ($platform).sublime-keymap", "default": "[\n\t$0\n]\n"}
command: new_window
The first of these is the appropriate command, and the second is that command executing a command of it's own to open a new window for the settings to be stored in.
Armed with that, you can make an appropriate key binding:
{
"keys": ["ctrl+alt+shift+k"],
"command": "edit_settings",
"args": {
"base_file": "${packages}/Default/Default ($platform).sublime-keymap",
"default": "[\n\t$0\n]\n"
}
},
Note that recent (as of the time of this answer) builds of Sublime have a bug in which commands executed from the command palette don't always get logged, in which case if that's how you want to determine the correct command you would have to look in the resource directly.

To add a more simple approach to OdatNurd's fantastic answer: I recently found myself wanting a shortcut to open my keybindings file and came across a slightly longer route using the Command Pallet that I was content with.
This doesn't answer the specific issue of creating a keyboard shortcut to open the user's .sublime-keymap file, but it does solve the general issue of getting to that file in a timely manner, without having to use the mouse.
The approach is:
Ctrl+Alt+P (Open Command Pallet)
Type: "keybind"
This gives:
Hit Enter and the user's .sublime-keymap file will be opened as it would be if you navigated to Menu > Preferences > Key Bindings.

Related

How to use file:duplicate from the palette using plugin in sublime text?

How to use File : duplicate option from the palette using plugin in sublime text ?
In order to see which command is being run when a particular action is being performed, open the console (Ctrl`) and run
sublime.log_commands(True)
Next, open the Command Palette (command: show_overlay {"overlay": "command_palette"} will show up in the console) and select File: Duplicate. The console will close, but when you reopen it you will see that command: side_bar_duplicate {} has been logged. At this point, you can enter
sublime.log_commands(False)
to stop logging, as it tends to fill the console with unnecessary garbage.
As you can see from the name of the command, File: Duplicate is from the SideBarEnhancements plugin (defined here) and is not built-in to Sublime. Therefore, if you are making a plugin for public distribution, you users will need to have SideBarEnhancements installed first.
To call this (or any) command in your plugin, simply put
window.run_command("side_bar_duplicate")
into your code at the appropriate location.
As #OdatNurd reminded me, because SideBarDuplicateCommand is a subclass of sublime_plugin.WindowCommand, it can only be run on an instance of sublime.Window.

Is there any shortcut-key in sublime text 3 to change language?

Actually there is an easy way to change language in Sublime Text 3, that's on the bottom right corner. But I need the fast way to change while my hands are on the keyboard. Is there any shortcut-key to change language in Sublime Text 3?
Thank you.
All of the non-hidden syntaxes in Sublime are automatically added to the View > Syntax main menu, which is the same menu that appears when you click on the file type in the bottom of the window. Additionally all syntaxes are added to the Command Palette as commands that start with Set Syntax:.
So the easiest and fastest non-mouse way to swap the syntax on a file is to open the command palette an enter just enough filter text to find and select the command that will swap to your desired syntax, such as in the image below to switch to HTML.
Sublime remembers what command you select for any given command palette input, so for extra speed you can use filter text like sh and manually select the Set Syntax: HTML command that appears to tell Sublime that's the command you want. Now whenever you enter sh it will automatically select that command for you by default.
The set_setting command can be used to set any setting, including the syntax setting, so you could also bind a key to that command to switch easily to an often used syntax. However that requires that you know the full package resource name of the syntax in question and it will not properly set up the syntax specific settings (that requires a plugin that uses view.assign_syntax()).
There may be a package available on package control that provides such a command already, but I'm not aware of any offhand.

Keybind for auto-indent/reindent block of code in ST3

Is there a way to add a keybind to reindent a highlighted block of code in Sublime Text 3?
I know there is a "reindent" option in Edit > Line > Reindent, but it has no keybind.
Also, that reindent funcion is not so "smart" and in some cases it gives weird results. Is there an addon that better solves this issue?
I mostly code in JavaScript if that helps.
Covering the first part of your question, it's possible to bind a key to anything that exists in the Menu or command palette, it's just a matter of finding out what command and arguments you need.
The easiest way to do that would be to open the Sublime console with Ctrl+` or View > Show Console, then enter the command sublime.log_commands(True), execute the command and see what it says:
>>> sublime.log_commands(True)
command: reindent {"single_line": true}
You can run the command command with False instead of True to turn off logging, or just restart Sublime.
With that knowledge, you can create a key binding using the command and arguments that were displayed by using Preferences > Key Bindings and adding the binding in the right hand pane.
In this case, that woulld look something like this (change the key as appropriate):
{
"keys": ["ctrl+alt+r"],
"command": "reindent",
"args": {
"single_line": true
}
},
Once you do this, not only is the key binding active but Sublime will also display the key that you selected in the menu next to the menu item as an extra reminder for you.
For the second part of your question, indeed the internal reindent and reformat of code is not ideal in Sublime; partially this is the result of its indentation system being powered by some simple regular expressions in the same manner as TextMate for compatibility reasons.
In any case, you can search Package Control for third party packages that might allow for better formatting/reformatting of code. In the case of JavaScript, something like JsFormat might be what you want.
Typically such a package only provides integration with an external tool that does the work and thus requires you to also install an external third party tool to function. In the specific case of JsFormat however, it bundles it's own formatter directly.

Keyboard shortcut to show/hide tabs in ST3 Win10

I was reviewing several pages but I can not make Sublime Text 3 have a hot key where you can show and hide the Tabs quickly, read this link where it talks about it but it seems that there is no such combination, someone who could do it ?
Pd: I do not want to do it from the menu, i want is by keyhots
In order to bind a key to this, you need to know what command to use in the key binding. The easiest way to determine that would be to select View > Show Console from the menu to open the console, then enter sublime.log_commands(True) to turn on command logging, and execute the command that you want to bind.
In this case, that would be View > Hide Tabs (or View > Show Tabs, depending on if they're visible or not), which allows us to see this in the console:
>>> sublime.log_commands(True)
command: toggle_tabs
Armed with the command, you can select Preferences > Key Bindings and add your own key binding in the right hand pane, such as this one:
{
"keys": ["ctrl+alt+t"],
"command": "toggle_tabs"
},
Naturally you can choose any key binding that you'd like here. Once you do this, the menu command and the command palette entries for toggling the tab state will show the key you selected next to them to remind you.
Note that if this is your first custom key binding, you want to make sure that you add the binding inside of the [ and ] characters that will appear in the file. If you have other bindings, make sure that you separate each binding with a , character.

Recall previous command in the RubyMine console

In the RubyMine consoles, like the one that appears in RubyMine 7 while debugging, how do you recall the previous command or line you typed? Something similar to pressing the up arrow in a conventional terminal or console.
The history of commands can be accessed similar to any conventional terminal or console :- using the up and down arrows to scroll through the history.
The commands history size limit can be specified in : File|Settings|Editor - "Console commands history size"
Scrolling through console history with the up key in any command line environment can be pretty tedious. option-command-E, can show you your entire commands history.
Looking into RubyMine 7.0 Doc
https://www.jetbrains.com/ruby/webhelp/using-consoles.html
In an interactive console, you can:
Type commands in the lower pane of the console, and press Enter to
execute them.
Results are displayed in the upper pane. Use basic code completion
Ctrl+Space.
Use Up and Down arrow keys to scroll through the history of
commands, and execute the required ones.
Load source code fom the editor into console.
Use context menu of the upper pane to copy all output to the
clipboard, compare with the current contents of the clipboard, or
remove all output from the console.
Use the toolbar buttons to control your session in the console.
Configure color scheme of the console to meet your preferences.
Refer to the section Configuring Color Scheme for Consoles for
details.

Resources