Sublime Text 3 toggle on/of side bar shortcut - sublimetext3

I want to have a shortcut for showing/hiding the side menu, because I mainly use sublime on a flipped monitor.
I tried this but it doesn't work...
[
{"keys": ["ctrl+alt+q"], "command": "show_side_bar"}
]
t

The command is actually toggle_side_bar.
This can be discovered for any command or action by opening the console (Ctrl`) and running
sublime.log_commands(True)
Run whichever commands you wish, and the command names along with any runtime parameters will show up in the console. When you're done, it's usually a good idea to run
sublime.log_commands(False)
to avoid your console filling up with nonsense, such as every single key you press.
By the way, there already is a keyboard shortcut for showing and hiding the side bar: CtrlK,CtrlB. That means hit CtrlK, release them, then hit CtrlB.

Related

Sublime text shortcut to open keybindings and settings

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.

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.

How can be define the key shortcut to save a project in Sublime Text 3?

What is the keybinding command to save the current a project in Sublime Text 3? As shown in the image.
I've tried this one, but it doesn't appear as shortcut inside the menu.
{"keys": ["ctrl+alt+s"], "command": "save_project_as"}
Thank you.
{"keys": ["ctrl+alt+s"], "command": "save_project_and_workspace_as"}
More Info
There's no key binding for that by default (as you've noticed), but the command you want is save_project_and_workspace_as.
The easiest way to see what any menu, command palette entry or key binding is doing is to open the Sublime console with Ctrl+` or View > Show Console from the menu and then enter the command:
sublime.log_commands(True)
Once you've done that, take an action (e.g. select the menu item) and the console will tell you what command it ran and what arguments it takes.

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