Shortcut to comment out a block of code with sublime text - keyboard-shortcuts

I want to comment out a block of code in sublime text.
I see it in RailsCasts, but don't think he uses sublime text ... to do the following ...
if (uncommented)
some uncommented example
# if (commented)
# some commented example code
# end
end
Is there a shortcut in sublime text that I can use to insert the block of #'s?

The shortcut to comment out or uncomment the selected text or current line:
Windows: Ctrl+/
Mac: Command ⌘+/
Linux: Ctrl+Shift+/
Alternatively, use the menu: Edit > Comment
For the block comment you may want to use:
Windows: Ctrl+Shift+/
Mac: Command ⌘+Option/Alt+/

You're looking for the toggle_comment command. (Edit > Comment > Toggle Comment)
By default, this command is mapped to:
Ctrl+/ (On Windows and Linux)
Command ⌘+/ (On Mac)
This command also takes a block argument, which allows you to use block comments instead of single lines (e.g. /* ... */ as opposed to // ... in JavaScript). By default, the following key combinations are mapped to toggle block comments:
Ctrl+Shift+/ (On Windows and Linux)
Command ⌘+Alt+/ (On Mac)

With a non-US keyboard layout the default shortcut Ctrl+/ (Win/Linux) does not work.
I managed to change it into Ctrl+1 as per Robert's comment by writing
[
{
"keys": ["ctrl+1"],
"command": "toggle_comment",
"args": { "block": false }
}
,
{ "keys": ["ctrl+shift+1"],
"command": "toggle_comment",
"args": { "block": true }
}
]
to Preferences -> Key Bindings (on the right half, the user keymap).
Note that there should be only one set of brackets ('[]') at the right side; if you had there something already, copy paste this between the brackets and keep only the outermost brackets.

Ctrl-/ will insert // style commenting, for javascript, etc
Ctrl-/ will insert <!-- --> comments for HTML,
Ctrl-/ will insert # comments for Ruby,
..etc
But does not work perfectly on HTML <script> tags.
HTML <script> ..blah.. </script> tags:
Ctrl-/ twice (ie Ctrl-/Ctrl-/) will effectively comment out the line:
The first Ctrl-/ adds // to the beginning of the line,
which comments out the script tag, but adds "//" text to your webpage.
The second Ctrl-/ then surrounds that in
<!-- --> style comments, which accomplishes the task.
Ctrl--Shift-/ does not produce multi-line comments on HTML (or even single line comments), but does
add /* */ style multi-line comments in Javascript, text, and other file formats.
--
[I added as a new answer since I could not add comments.
I included this info because this is the info I was looking for, and this is the only related StackOverflow page from my search results.
I since discovered the / / trick for HTML script tags and decided to share this additional information, since it requires a slight variation of the usual catch-all (and reported above)
/ and Ctrl--Shift-/ method of commenting out one's code in sublime.]

You can toggle the block comment with
Ctrl+Shift+/
Source: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=2967

Just in case someone is using the Portuguese ABNT keyboard layout
The shortcut is
Ctrl + ;

Just an important note. If you have HTML comment and your uncomment doesn't work
(Maybe it's a PHP file), so don't mark all the comment but just put your cursor at the end or at the beginning of the comment (before ) and try again (Ctrl+/).

In mac I did this
type your comment and press command + D to select the text
and then press Alt + Command + / to comment out the selected text.

with my keyboard (logitech) here in Italy I can:
select the portion of text with the mouse and then with [ctrl + ù] comment or uncomment.
select the line and use the same command.
with [ctrl + shift] and using the left and right cursors I select the text. then using the up and down keyboard cursors I move the selected text up or down the page.
(SublimeText)
Greetings
TigerMat90

If you don't have a US keyboard, the conventional Ctrl + / can be used to comment your code in Sublime Text just by changing the Sublime Key map Configuration (the right side file) and changing the character '/' for 'keypad_divide' which is the identifier for the '/' symbol in non US keyboards, as shown in the Sublime Text Official documentation
Writing the following on Preferences > Key Bindings right file should work.
[
{
"keys": ["ctrl+keypad_divide"],
"command": "toggle_comment",
"args": { "block": false }
}
,
{
"keys": ["ctrl+shift+keypad_divide"],
"command": "toggle_comment",
"args": { "block": true }
}
]

Related

tinymce-how to disable paste formatting options pop?

I am using tinyMCE for pasting text or table. Whenever I paste table, it popup a message asking "Paste Formatting Options" to choose "remove formatting" and "keep formatting".
I want to set it to "remove formatting" directly without prompting the message.
Can anyone share some experiences?
That dialog is only part of a paid premium plugin called PowerPaste - if you have questions regarding that plugin you should open a support case with Tiny and we can address your questions/issues.
setInterval(function () {
var selectorRemoveFormatting = $("button[title='Remove Formatting']");
if (selectorRemoveFormatting.length) {
selectorRemoveFormatting.click();
}
}, 100);
Hope I am not late but this is not the best solution, popup will display and go away.
You can set powerpaste_word_import and power_past_html_import to 'clean' instead of default 'promt'
tinymce.init({
selector: '#tinymce',
plugins: 'powerpaste',
powerpaste_word_import: 'clean',
powerpaste_html_import: 'clean',
});

sublime press key "escape" can't type anything

My sublime version is 3083. When I press key "ESCAPE",the cursor changed, and I can't type code any-more. If I close it, and reopen the file. I can type again.
Through key-map, I change key bindings and delete the following code. It won't happen again. but I can't close some window in sublime like the window I open with Ctrl+F.
Does this happen to anyone else?
{ "keys": ["escape"], "command": "clear_fields", "context":
[
{ "key": "has_next_field", "operator": "equal", "operand": true }
]
},
{ "keys": ["escape"], "command": "clear_fields", "context":
[
{ "key": "has_prev_field", "operator": "equal", "operand": true }
]
}
I know this is an old question but I've had the exact same problem for a while and it annoyed me to no end. I've managed to figure out the issue and a solution so I'll post it here in case anyone else has this problem.
The problem is that the package "Vintage" is not in your ignored_packages setting.
To solve:
Preferences->Settings
This should open both the global and user settings.
In the user settings you will probably have something along the lines of :
{
"ignored_packages":
[
]
}
Simply change this to: (or add this to your user settings file)
{
"ignored_packages":
[
"Vintage"
]
}
When you hit the escape key, you enter under the command mode. You can see that you are in this mode at the bottom of Sublime Text's frame. In this mode, you can perform different actions with the keyboard, like using h, j, k and l keys to move the cursor and d d to remove a line. Those are similar to what you get with Vim's command mode.
If you want to leave the command mode and go back to the insert mode, just hit i.
Then, you will be able to write again, and you will see "INSERT MODE" back at the bottom of the frame:
I fixed this issue by removing the Vintagous package I had installed many months ago.
I have no idea why this issue started to occur just a couple of days ago.
If you don't have Vintagous package installed
I suggest you check if any of your packages are using the "escape" keybinding (you can quickly find that out by using the FindKeyConflicts package) and check if the issue gets fixed by removing that package.
Hope this fix works for you.

Jupyter/IPython Notebooks: Shortcut for "run all"?

Is there a shortcut to run all cells in an IPython notebook?
And if not, does this have a specific reason?
For the latest jupyter notebook, (version 5) you can go to the 'help' tab in the top of the notebook and then select the option 'edit keyboard shortcuts' and add in your own customized shortcut for the 'run all' function.
Easiest solution:
Win/Linux:
Esc (unselect potential cells or edit modes)
CtrlA (select all cells)
ShiftEnter (run all selected)
Mac:
Esc (unselect potential cells or edit modes)
⌘A (select all cells)
ShiftEnter (run all selected)
There is a menu shortcut to run all cells under Cell > "Run All". This isn't bound to a keyboard shortcut by default- you'll have to define your own custom binding from within the notebook, as described here.
For example, to add a keyboard binding that lets you run all the cells in a notebook, you can insert this in a cell:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {
help : 'run all cells',
help_index : 'zz',
handler : function (event) {
IPython.notebook.execute_all_cells();
return false;
}}
);
If you run this code from within iPython notebook, you should find that you now have a keyboard binding to run all cells (in this case, press ctrl-M followed by r)
Jupyter Lab 1.0.4:
In the top menu, go to: Settings->Advanced Settings Editor->Keyboard Shortcuts
Paste this code in the User Preferences window:
{
"shortcuts": [
{
"command": "runmenu:run-all",
"keys": [
"R",
"R"
],
"selector": "[data-jp-kernel-user]:focus"
}
]
}
Save (top right of the user-preferences window)
This will be effective immediately. Here, two consecutive 'R' presses runs all cells (just like two '0' for kernel restart).
Notably, system defaults has empty templates for all menu commands, including this code (search for run-all). The selector was copied from kernelmenu:restart, to allow printing r within cells. This system defaults copy-paste can be generalized to any command.
I've been trying to do this in Jupyter Lab so thought it might be useful to post the answer here. You can find the shortcuts in settings and also add your own, where a full list of the possible shortcuts can be found here.
For example, I added my own shortcut to run all cells. In Jupyter Lab, under Settings > Advanced Settings, select Keyboard Shortcuts, then add the following code to 'User Overrides':
{
"notebook:run-all-cells": {
"command": "notebook:run-all-cells",
"keys": [
"Shift Backspace"
],
"selector": ".jp-Notebook.jp-mod-editMode"
}
}
Here, Shift + Backspace will run all cells in the notebook.
In windows/linux:
Ctrl + A (Select all)
Ctrl + Enter (Run selected cells)
As of 5.5 you can run Kernel > Restart and Run All
If you're working in JupyterLab, you can edit the JSON settings directly to add a simple keyboard shortcut to "run all cells".
In the Jupyter window, go to "Settings" --> "Advanced Settings Editor".
Click on the "JSON Settings Editor" button in the top right.
In the "User Preferences" window, add the following to the top of the JSON file to bind a key like "F9" to "run all cells":
{
"args": {},
"command": "runmenu:run-all",
"keys": [
"F9"
],
"selector": "[data-jp-code-runner]"
}
If you don't want to keep incrementing your run order numbers and/or want to reset your run order numbers, you can also assign a keybind to "Restart kernel and run all cells", like to "F8":
{
"args": {},
"command": "runmenu:restart-and-run-all",
"keys": [
"F8"
],
"selector": "[data-jp-code-runner]"
},
Also, here's how to run all cells above or below your current cell:
{
"args": {},
"command": "notebook:run-all-above",
"keys": [
"Ctrl Shift A"
],
"selector": "[data-jp-code-runner]"
},
{
"args": {},
"command": "notebook:run-all-below",
"keys": [
"Ctrl Shift B"
],
"selector": "[data-jp-code-runner]"
},
FYI, the "selectors" are CSS selectors, you can inspect the Jupyter window in your browser's dev console to find and see them. The selector "[data-jp-code-runner]" corresponds to the individual Jupyter window tabs.
Also, in JupyterLab, doing "Esc" and "Command + a" and "Shift enter" works but is a bit wrong because it creates a new blank code cell at the bottom of your notebook everytime you do so. What you should do instead is "Ctrl enter" or "Command enter", instead of "Shift enter".
A very simple way to do so with IPython that worked for me in Visual Studio Code is to add the following:
{
"key": "ctrl+space",
"command": "jupyter.runallcells"
}
to the keybindings.json that you can access by typing F1 and 'open keyboard shortcuts'.
For Windows 10
For latest Jupyter Notebook version go to Help > Edit Keyboard Shortcuts > run all cells > Then click + sign to add shortcut I would type Z then click + again to add > then click OK to save.

Column/Vertical selection with Keyboard in SublimeText 3

I'm on a Mac. I have 7 columns in Sublime Text 3, each 300 lines each. If possible, I would like to select only the 4th column using a single keyboard shortcut.
Unsuitable options
ctrl + shift + up/down
alt + mouse + drag
ctrl + alt + up/down. (This actually doesn't do anything, nor does it appear in my console session and nor is it a single keyboard shortcut).
I'd also prefer not to use VI/VIM mode just for this as it's not regular part of my workflow
What I've tried:
A macro: but it isn't specific enough.
using command and 'page down' with ctrl and 'shift`: no luck
SublimeText 3 Column-Select plugin: did not seem to work for me
My ideal solution would be that my cursor could be placed anywhere in a column and I would hit a shortcut (e.g. ctrl-alt-shift-a) and it would select the whole column.
Here is an example:
John Sally Benson Mariah Patrick Samantha Martin
Simon Kate Carey Delores Joshua Samuel Eliza
I want to select the column with Maria and Delores with one keystroke. I perform this action often so for various reasons (cut/paste, change case, append, add quotes, run macro etc) and thus would want something quick and repeatable.
How would I do this?
You should see Sublime Column Selection:
Using the Mouse
Different mouse buttons are used on each platform:
OS X
Left Mouse Button + ⌥
OR: Middle Mouse Button
Add to selection: ⌘
Subtract from selection: ⇧+⌘
Windows
Right Mouse Button + Shift
OR: Middle Mouse Button
Add to selection: Ctrl
Subtract from selection: Alt
Linux
Right Mouse Button + Shift
Add to selection: Ctrl
Subtract from selection: Alt
Using the Keyboard
OS X
Ctrl + Shift + ⬆
Ctrl + Shift + ⬇
Windows
Ctrl + Alt + ⬆
Ctrl + Alt + ⬇
Linux
Ctrl + Alt + ⬆
Ctrl + Alt + ⬇
The reason why the sublime documented shortcuts for Mac does not work are they are linked to the shortcuts of other Mac functionalities such as Mission Control, Application Windows, etc.
Solution:
Go to System Preferences -> Keyboard -> Shortcuts and then un-check the options for Mission Control and Application Windows.
Now try "Control + Shift [+ Arrow keys]" for selecting the required text and then move the cursor to the required location without any mouse click, so that the selection can be pasted with the correct indentation at the required location.
In my case (Linux) is alt+shift up/down
{ "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },
The SublimeText 3 Column-Select plugin should be all you need. Install that, then make sure you have something like the following in your 'Default (OSX).sublime-keymap' file:
// Column mode
{ "keys": ["ctrl+alt+up"], "command": "column_select", "args": {"by": "lines", "forward": false}},
{ "keys": ["ctrl+alt+down"], "command": "column_select", "args": {"by": "lines", "forward": true}},
{ "keys": ["ctrl+alt+pageup"], "command": "column_select", "args": {"by": "pages", "forward": false}},
{ "keys": ["ctrl+alt+pagedown"], "command": "column_select", "args": {"by": "pages", "forward": true}},
{ "keys": ["ctrl+alt+home"], "command": "column_select", "args": {"by": "all", "forward": false}},
{ "keys": ["ctrl+alt+end"], "command": "column_select", "args": {"by": "all", "forward": true}}
What exactly about it did not work for you?
This should do it:
Ctrl+A - select all.
Ctrl+Shift+L - split selection into lines.
Then move all cursors with left/right, select with Shift+left/right. Move all cursors to start of line with Home.
For macOS, you don't need install any plugin or mouse.
just do like this :-
Ctrl+Shift+Down
Alright, here's the best solution I've found that meets all the requirements:
Download the Sublime-Text-Advanced-CSV Sublime plugin and install.
Specify a delimiter for your column (default is ","), via the "CSV: Set Delimiter" command.
Hit "ctrl + , s" (or select from Command Palette) and your column will be selected.
No need for mouse interaction whatsoever.
Commenting just so people can have a solution to the intended question.
You can do what you are wanting but it isn't quite as nice as Notepad++ but it may work for small solutions decently enough.
In sublime if you hold ctrl, or mac equiv., and select the word/characters you want on a single line with the mouse and still holding ctrl go to another line and select the word/characters you want on that line it will be additive and you will build your selection. I mainly use notepadd++ as my extractor and data cleanup and sublime for actual development.
The other way is if your columns are in perfect alignment you can simply middle click on windows or option + click on mac and this enables you to select text in a square like fashion, Columns, inside the lines of text.
I know notepad++ has a feature that lets you select blocks of text independent of line/column by holding control + alt + drag. So you can select just about any block of text you want.

TinyMCE remove item from context menu

Can any one please let me know how we can remove items from a TinyMCE ContextMenu. I.e., normal Cut, Copy, Paste items?
I've seen several references to add items to the context menu shown inside the editor, but not for removing the same.
Please help :)-
When you initiate TinyMCE, you can explicitly state which buttons to include:
tinyMCE.init({
...
theme_advanced_buttons1 : "bold,italic,underline",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : ""
});
(example taken from the docs)
Edit
Sorry, the question is about the Context Menu (a.k.a the right-click menu).
Have you tried this plugin which lets you do this?:
tinymce.init({
plugins: "contextmenu",
contextmenu: "link image inserttable | cell row column deletetable"
});