How to differentiate between two Sublime windows - sublimetext3

I am running two Sublime windows at the same time. In one window I'm getting code to update the other one. Both are using the same color pattern, so I am confused between them.
My question is, is there a way to distinguish in between the windows? Making color-scheme different, or something like that?

This can be done with a very simple plugin and key binding. First, select Tools -> Developer -> New Plugin... and replace the contents with the following:
import sublime_plugin
class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
def run(self):
for view in self.window.views():
view.settings().set("color_scheme",
"Packages/Color Scheme - Default/Cobalt.tmTheme")
You should change "Packages/Color Scheme - Default/Cobalt.tmTheme" to whichever color scheme you'd like to use in the window. Save the file as Packages/User/change_window_color_scheme.py - if you just go to File -> Save it should automagically open to Packages/User.
Next, create a new key binding by selecting Preferences -> Key Bindings-User and adding the following if the file is empty:
[
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" }
]
If you already have some custom key bindings, add the following on the line following the opening square bracket [:
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" },
Save the file, and everything should be all set. Select the window you'd like to change the color scheme for, then hit CtrlAltShiftC, S - meaning you hit CtrlAltShiftC, release them, and hit S. You can change the key binding if you wish, of course.

Related

How to disable multiple instances of cursors in Sublime Text 3?

Environment
Sublime Text: 3.1.1, Build 3176
Windows 10
Undesired Behaviour
I must have unintentionally pressed a keyboard combination as I have not had this issue before.
I cannot identify what circumstances create the undesired behavior, but sometimes this happens:
ie, I will be editing some text and realise that the cursor is in 2 (possibly more?) places and everything i am typing is also appearing in multiple places.
Edit: It seems to sometimes occurs after I have Ctrl + V / Ctrl + Shift + V pasted content.
What I've Tried
I've looked at this link, as the title sounded like it might be related:
https://www.sublimetext.com/docs/3/multiple_selection_with_the_keyboard.html
But on closer reading it doesn't seem to be.
I think the following answer might explain the behaviour, but not how to disable it:
https://stackoverflow.com/a/46800245
Desired Behaviour
I'd like to know how to disable the undesired behaviour.
Multiple Cursors on Sublime3, is activated by default either with
ctrl+left mouse button
or by
ctrl+shift+l
disabling ctrl+shift+l:
setting is called split_selection_into_lines. to disable it (Windows):
click Preferences, Key Binding, and on the file Default (Windows).sublime-keymap that will open add the line. (
{ "keys": ["ctrl+shift+l"], "command": "" },
be sure to put this inside the default brackets [ ].
Same is for Linux or Mac, only thing changes is the operating system name on the filename.
disabling ctrl+left mouse button:
Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User
Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User
Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User
open it with a text editor and paste the following lines in it:
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "",
"command": ""
}
]
Save and you are done. In my test, (win10, sublime text 3) method worked instantly, without even restarting Sublime Text 3.

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.

sublimetext - Multiple binding command

I'm a long time VS user, and I have gotten used to doing the following in order to comment out multiple lines of code:
Ctrl+K and Ctrl+C
Likewise, uncommenting requires this:
Ctrl+K and Ctrl+U
Now I am switching to Sublime Text 3 for specific types of projects, and I would like to use the same bindings. I have transferred most bindings I commonly use, but I can't find a way to use the same "double" binding in Sublime. Is it possible?
And to be clear, of course I could un-learn the binding and use Sublime's, maybe even tweak VS to use that as well. However, I'd much rather use the one (ones?) I already know.
Go to Preferences -> Key Bindings
You will have 2 view layouts
for Default key bindings that sublime provides.
for user defined key bindings
Click on the user defined layout (right side layout) and write following code into the file to make comment using ctrl+k
[
{ "keys": ["ctrl+k"], "command": "toggle_comment", "args": { "block": false } }
]

Resources