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.
Related
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.
I'm developing a Sublime Text 3 plugin which uses the quick panel a.k.a. the command palette.
I would like to add a textual title/label at the top of the quick panel when the user opens my plugin's quick panel menu, because my plugin runs in various modes and I want to make it clear which mode is currently running (Test, Pre-Live, Live, etc.)
Is this possible, and how?
This a mockup of what I want to achieve:
This is not possible in a quick panel, no. The only thing you can provide to the quick panel display-wise is the list of items that you want the user to choose from. Each item in the list can contain multiple lines of data however (with the restriction that every row has to contain the same number of lines):
Something like that could potentially be used to provide context on the items in the list that allows the user to know what mode you're in.
The Command Palette and the quick panel aren't the same thing (although they are visually similar); the command palette only displays commands that you can choose. By using an input handler, you can customize the display somewhat:
In this sample, View Package File is the selected command, but the command has control over what that text says (it's just the command name by default). You also have the power to provide a "preview" (basically any extra information that you want) about the currently selected item:
So given that, depending on your use case your command could present its interface in the command palette to give this kind of contextual clue.
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.
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.
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.