How to comment the selected or the highlighted text in sublime text 3 on a macbook.
Cmd + /
will comment out the whole line and not the selected part - should I just create a key mapping for this or is there an existing mapping??
To block comment a selection the command is ( option + command + / ):
⌥ + ⌘ + /
Example:
{
"shell_cmd": /*"make"*/
}
↳ Sublime Keyboard Shortcuts - OS X
Related
I am a full-time .NET Developer, so I work in Windows 10 at work; however, I definitely prefer macOS and use it at home. I am a constant user of the Home and End keys and they make me so much more efficient. Is there any way to force the Home and End keys on macOS to behave like Windows 10?
What I Want
Home: Sends cursor to beginning of current line
End: Sends cursor to end of current line
Shift-Home: Sends cursor to beginning of current line with selection
Shift-End: Sends cursor to end of current line with selection
Command-Home: Sends cursor to beginning of current document
Command-End: Sends cursor to end of current document
Shift-Command-Home: Sends cursor to beginning of current document with selection
Shift-Command-End: Sends cursor to end of current document with selection
What I've Tried
A simple Google search provided me with the possible solution of adding custom NSResponder entries in ~/Library/KeyBindings/DefaultKeyBinding.dict and rebooting. Unfortunately, that does not seem to have worked. I have tested it in Xcode, Sublime Text, and Safari. The keys appear to behave in the normal macOS manner.
{
"\UF729" = "moveToBeginningOfLine:";
"\UF72B" = "moveToEndOfLine:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"$\UF72B" = "moveToEndOfLineAndModifySelection:";
}
I have also tried using BetterTouchTool to set a keyboard shortcut mapping Home to Command-Left and End to Command-Right. That works for Home and End but it doesn't work for the selecting text nor for navigating the document
What I'm Using
Mid-2012 non-Retina MacBook Pro
macOS High Sierra Public Beta 5
Apple Magic Keyboard
Xcode, Sublime Text, Safari specifically
Bonus Points
Command-Left: Sends cursor to beginning of word
Command-Right: Sends cursor to end of word
Shift-Command-Left: Sends cursor to beginning of word with selection
Shift-Command-Right: Sends cursor to end of word with selection
I'm not exactly sure what I changed, but it suddenly started to work. Here is my DefaultKeyBinding.dict. Here is a pastebin to the raw file.
{
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"#\UF729" = "moveToBeginningOfDocument:"; /* Cmd + Home */
"#\UF72B" = "moveToEndOfDocument:"; /* Cmd + End */
"#$\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Cmd + Home */
"#$\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Cmd + End */
"#\Uf702" = "moveWordLeft:"; /* Cmd + Left */
"#\Uf703" = "moveWordRight:"; /* Cmd + Right */
"#$\Uf702" = "moveWordLeftAndModifySelection:"; /* Shift + Cmd + Left */
"#$\Uf703" = "moveWordRightAndModifySelection:"; /* Shift + Cmd + Right */
}
How can I remove the non-breaking spaces that appear when I click Shift + Alt + Space? They are really annoying when writing code since they produce errors.
I have tried adding the following to DefaultKeyBinding.dict:
{
"~ " = ("insertText:", " ");
}
I would like it to work in both Coda + PhpStorm. Thanks!
Is there a way to customise XCode comment actions. Example:
original
func thisfunc() {
var x = 5
}
when commented (cmd + /)
func thisfunc() {
// var x = 5
}
not
func thisfunc() {
// var x = 5
}
In the default behaviour XCode puts the comment in the beginning of the line but I want it to be like the first commented example (like sublime text comment blocks).
I don't think you can customize XCode the way you want. However there's still a way to do it by the steps are (1) selecting commented code (2) cmd + [ (3) cmd + / (4) ctrl + i. Have a try and this is not that complicated.
Is there a way/plugin in sublime text 3 for highlighting multiple character offset ranges? The ideal desired functionality would be something like this: given a range of character offsets (e.g. 200-400, 5000-5300, 6400-6450) highlight the corresponding ranges.
This can be done with a WindowCommand plugin. Go to Tools -> New Plugin... and replace the contents with the following:
import sublime
import sublime_plugin
class SelectRegionCommand(sublime_plugin.WindowCommand):
def highlight_region(self, regions):
region_list = []
if "," in regions:
for region in regions.split(","):
region_list.append(tuple(region.split("-")))
else:
region_list.append(tuple(regions.split("-")))
view = self.window.active_view()
view.show(int(region_list[0][0]))
for region in region_list:
begin = int(region[0])
end = int(region[1])
to_highlight = sublime.Region(begin, end)
view.sel().add(to_highlight)
def run(self):
message = "Enter offset range(s) to select, separated by commas:"
default = "0-100"
self.window.show_input_panel(message, default, self.highlight_region, None, None)
Save the file as Packages/User/select_region.py (it should open that directory automatically), where Packages is the directory opened by selecting Preferences -> Browse Packages....
Next, create a custom key binding to trigger the plugin. Open Preferences -> Key Bindings-User and add the following line:
{ "keys": ["ctrl+alt+shift+s"], "command": "select_region" }
If the file is empty, surround the key binding with square brackets [ ]. Save the file, and you're all set. Hitting CtrlAltShiftS will bring up an input panel at the bottom of the window where you can enter the character offsets. Please don't include any spaces, so your input should look like the following:
Hit Enter, and the regions you entered will be selected:
EDIT
I altered the code slightly so that the view scrolls to the beginning of the first region entered (it should be centered on the screen). If you don't want that functionality for some reason, just comment out the view.show(int(region_list[0][0])) line (line 14).
I have several strings selected in a file in Sublime Text and I want to convert them all to lowercase.
How can I convert them all to lowercase in Sublime Text?
From the Sublime Text docs for Windows/Linux:
Keypress Command
Ctrl + K, Ctrl + U Transform to Uppercase
Ctrl + K, Ctrl + L Transform to Lowercase
and for Mac:
Keypress Command
cmd + KU Transform to Uppercase
cmd + KL Transform to Lowercase
Also note that Ctrl + Shift + p in Windows (⌘ + Shift + p in a Mac) brings up the Command Palette where you can search for these and other commands. It looks like this:
For Windows:
Ctrl+K,Ctrl+U for UPPERCASE.
Ctrl+K,Ctrl+L for lowercase.
Method 1 (Two keys pressed at a time)
Press Ctrl and hold.
Now press K, release K while holding Ctrl. (Do not release the Ctrl key)
Immediately, press U (for uppercase) OR L (for lowercase) with Ctrl still being pressed, then release all pressed keys.
Method 2 (3 keys pressed at a time)
Press Ctrl and hold.
Now press K.
Without releasing Ctrl and K, immediately press U (for uppercase) OR L (for lowercase) and release all pressed keys.
Please note: If you press and hold Ctrl+K for more than two seconds it will start deleting text so try to be quick with it.
I use the above shortcuts, and they work on my Windows system.
As a bonus for setting up a Title Case shortcut key Ctrl+kt (while holding Ctrl, press k and t), go to Preferences --> Keybindings-User
If you have a blank file open and close with the square brackets:
[ { "keys": ["ctrl+k", "ctrl+t"], "command": "title_case" } ]
Otherwise if you already have stuff in there, just make sure if it comes after another command to prepend a comma "," and add:
{ "keys": ["ctrl+k", "ctrl+t"], "command": "title_case" }
For Windows OS
For Uppercase
CTRL + K + U
For Lowercase
CTRL + K + L
For others needing a key binding:
{ "keys": ["ctrl+="], "command": "upper_case" },
{ "keys": ["ctrl+-"], "command": "lower_case" }