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 } }
]
Related
I'm using SublimeText3 and wanted to know if there is an option (package) which can be used to
Find references within the file.
Find references within the folder.
Goto definition.
I found a command called Goto->Reference, but this does not work for the current file and seems buggy.
I also found a package called wordhighlighter which is very useful.https://github.com/SublimeText/WordHighlight. I want to use this to navigate among highlighted words. Is there any keyboard shortcut to achieve this? There is an option to expand and collapse the selection but thats about it.
For someone else who comes up with the same issue, I found the answer here
How to navigate between instances of selected text in Sublime Text 3?
{ "keys": ["alt+super+g"], "command": "find_under" },
{ "keys": ["shift+alt+super+g"], "command": "find_under_prev" },
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.
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.
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.
I'm using the newest build (3033) of Sublime Text 3 on OS X 10.8
(This also was happening in build 3021)
I've setup some shortcuts to open an overlay of custom commands using the following in my sublime-keymap file:
{ "keys": ["command+f1"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "PHP"} }
I've noticed recently the using the down arrow works to navigate the menu but for some reason the up arrow does not in the way it used to. The up arrow works if I down arrow a few items then use up to go back up but it does not work to wrap from the first item to the last item on the overlay. Sublime Text 2 did (and still does) this on my computer.
Am I missing something? (it's mildly frustrating)
UPDATE
If I do a command + shift + P to open the Command Pallet or command + R to open the Goto Symbol overlay the up arrow does not work when trying to wrap around the list. It does in ST2.
ADDTIONAL UPDATE
Now on OS X 10.11 and Sublime Text 3 build 3103 and still the up arrow does not work.
I also posted this here: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12333
This behavior is still true (Sublime Text 3 Build 3103). Seems to be a software limitation (feature?) since they encourage the use of the fuzzy search bar that comes with the overlay window.
Also, there is no preference/setting that enables the wrapping.
It would be nice to have it.