How do I comment or uncomment code in Textmate 2?
I came across How do I use a shortcut to comment out code automatically in Textmate? , but it's for Textmate 1.x, and "Bundles" > "Source" > "Comments" doesn't have "Comment line".
I'm using TextMate 2.0-beta.7.1.
I recall disabling command + / because it was causing problems while working on Rails apps, but I assumed that would just disable the keyboard shortcut, not the ability to comment and uncomment lines.
In TextMate 2.0.19 you can comment, or uncomment, a line or selection with the shortcut Cmd (⌘) + /.
If this shortcut doesn't work for you, you can do it like this :
Select Bundles in the menu bar
Select Source
Select Comments
Select Comment line
Happy coding 🖖
TIPS
Define a new shortcut for comment or uncomment
If the native shortcut doesn't work for you, define a new one like this :
Select Bundles in the menu bar
Select Edit Bundles...
Select Source
Select Menu Actions
Select Comments
Select Comment Line / Selection
Click on Key Equivalent
Type your shortcut
Close the Bundles editor
A prompt will ask you to confirm your changes
Test it!
Others useful shortcuts
Insert Block Comment : Option (Alt, ⌥) + Cmd (⌘) + /
Insert Comment Banner: Select the word or text you want to use as a banner and Ctrl (⌃) + Shift (⇧) + B
Insert Comment Header ( This will insert the name of the script and some useful details): You have to define it 😅 because in my case it was empty... I defined it with Ctrl (⌃) + Shift (⇧) + N
Use Help in TextMate 😉
Select Help in the menu bar
type "comment"
This will brings you directly to the option comment line. I suggest doing that first because in most cases, you will find the answer.
Bundles -> Source -> Menu Actions -> Comments -> Comment Line
Is that what you're looking for?
Related
I want to modify the beginning of every line of a txt file in Geany. Somehow it is possible to write in multiple lines at the same time (maybe with box selection?).
How to do this?
You need to install before the plugin Extra Selection.
For my configuration (Debian/Buster, Geany 1.33) I add to configure shortcuts key.
See plugin manual for more details :
Usage :
Under Tools -> Extra Selection, there are 7 new items: "Column
Mode", "Select to Line", "Select to Matching Brace", "Toggle
Rectangular/Stream", "Set Anchor", "Select to Anchor" and "Rectangle
Select to Anchor". Normally these should be bound to keys, for example
Alt-C, Alt-Shift-L, Ctrl-Shift-B, Ctrl+2, F12, Shift-F12 and
Alt-Shift-F12.
This is just an addition to the answer by #zaboop since the edit queue was full and many people might not have understood the solution properly.
In Geany you cannot edit different parts of multiple lines at once (like in VS Code) without using plugins.
Instead what you can do is you can edit the starting of multiple lines at once.To do so:
Hold Shift + Alt and press your up or down arrow keys to correspondingly select the lines above or below the current line.
Then release Shift + Alt and continue editing the lines.
No plugins needed.
Strangely, unlike the other answers, I had to press Shift + Ctrl while selecting a region, and selecting only works with the mouse, not with the keyboard. After selecting, I was able to edit multiple lines at once.
Configuration: (Debian-based) Raspberry Pi OS, accessed via VNC, Geany 1.33
Select the region, while pressing Alt-Shift, then move around with cursor with arrows.
I'm searching for useful Android Studio keyboard shortcut for commenting code, as in Sublime Text or Eclipse.
When I press either cmd+/ or cmd+maj+/ nothing happens...
Mac With Numeric pad
Line Comment hold both: Cmd + /
Block Comment hold all three: Cmd + Alt + /
Mac
Line Comment hold both: Cmd + + =
Block Comment hold all three: Cmd + Alt + + =
Windows/linux :
Line Comment hold both: Ctrl + /
Block Comment hold all three: Ctrl + Shift + /
Same way to remove the comment block.
To Provide Method Documentation comment type /** and press Enter just above the method name (
It will create a block comment with parameter list and return type like this
/**
* #param userId
* #return
*/
public int getSubPlayerCountForUser(String userId){}
In spanish keyboard without changing anything I can make a comment with the keys:
cmd + -
OR
cmd + alt + -
This works because in english keyboard / is located at the same place than - on a spanish keyboard
Be sure you use the slash (/) on right side of keyboard.
For Line Comment:
Ctrl + /
For Block Comment:
Ctrl + Shift + /
You can see all keymap in Android Studio: Help ➤ Default Keymap Reference
On Mac and Turkish Keyboard it is (both for commenting out and uncommenting)
line comment:
cmd +.
block comment:
cmd+alt +.
An Example for a Mac OS X 10.5+ with a German layout keyboard without NumPads:
Open Preferences
Search for "Keymap"
Expand "Main menu"
Expand "Code"
Delete all shortcuts (just a suggestion)
Add a shortcut for a single line comment (e.g. Ctrl++)
Add a shortcut for a block comment (e.g. Ctrl+alt +)
This way you can be sure that those keys are not mapped (except if you assigned them before to another function)
Reviewing and Changing Keyboard Shortcuts in Android Studio
Keyboard shortcuts can be configured (and reviewed) via the Settings dialog, accessible via File -> Settings.
Once this dialog appears, to review (and/or add) a shortcut, do the following:
Select Keymap in the list on the left. Note that there is a "Keymaps" option, and depending on the original selection, shortcuts assigned to a given feature differ based on the Keymap.
Type "comment" or text corresponding to the feature for which the keyboard shortcut is to be reviewed/assigned. Each match has a line entry in the list below, and keyboard shortcuts are shown right-justified along with the feature. For example, both CTRL+ALT+SLASH and CTRL+K, CTRL+C are the two assignments for creating a line comment.
To modify a shortcut:
Select the resultant line corresponding to the feature for which the keyboard shortcut is to be reviewed/assigned
Right-click, and select the desired Add or Remove option.
Comment method like pro developers:
Windows/linux:
Line Comment : Ctrl + /
Block Comment : Ctrl + Shift
Method Commenting:
Type `/**` and press `Enter Key`
it will add the comment snippet like we see in standard documentation, give it a try this once.
/**
*
* #param addOpacity
*/
public void setOpacityOnUserImage(boolean addOpacity) {
// Your business logic.
}
In Android studio CTRL + SHIFT + / for windows.
for German Layout (Deutsches Layout) the default is:
for line Comment:
strg + Numpad(/)
for block Comment:
strg+shift+Numpad(/)
I use this sequence (not a 'linear' shortcut but useful anyway):
alt+c then alt+b (holding alt) for block comment
alt+c then alt+l (holding alt) for line comment
(they use the android studio menu)
On PC it's by default set to Ctrl + /. This will toggle commenting a selection or current line.
I am working with a german keyboard and the slash (/) is on the 7 key, meaning access would be Ctrl + Shift + 7. However, this does not work as this is predefined as something with bookmark 7.
I went to settings (search for keymap) and deleted all existing shortcuts. I than added Ctrl + 7, confirmed deletion of bookmark shortcut and now can work well.
For Line Comment: Ctrl + /
For Block Comment: Ctrl + Shift + /
For multiline comment in android studio
select the statement that you want to commented then
use ctrl+shift+/
and for removing mutiline comment
select the statement that you want to uncommented then
use **ctrl+shift+/**
SINGLE LINE COMMENT
For single line comment
use ctrl+/
Ctrl + Shift + / works well for me on Windows.
In LINUX
1.Single line commenting. Ctrl + /
2.For block comment Ctrl + Shift + /
on mac, using uk english keyboard layout to reach quickcomment in android studio the key combination is:
cmd + alt(option) + /
Mac (French-Canadian Keyboard):
Line Comment hold both: Cmd + É
Block Comment hold all three: Cmd + Alt + É
"É" is on the same position as "?/" in english one.
Are you sure you are using / and not \ ?
On Mac I have found by default:
Cmd + /
Comments using // notation
Cmd + Opt + /
Comments using /* */ notation
If you are used with Eclipse, there is something in Settings>Keymap Keymaps: and you can pick Eclipse to keep the same shortcuts.
For Line Comment hold both:
Ctrl + /
For Block Comment hold all three:
Ctrl + Shift + /
Same way to remove the comment block.
In android studio you can do
single comment with (go to line then Ctrl+/)
and
block comment with ( select text then Ctrl+Shift+/)
Also if you want to change color of commented text
go to File->Settings->IDE settings->Editor->Color & fonts->Java->(Line comment or block comment) and change properties.
I prefer it to be green which is used in notepad++ editor.
In the Icelandic MAC keyboard: CMD + -
You can add three slashes.
/// Add comments
this can clear the "comment out code 2 lines" issues.
Mac:
To comment/uncomment one line, use: Ctrl + /.
To comment/uncomment a block, use: Ctrl + Shift + /.
I noticed that command Ctrl + Shift + / works on Windows only in case if there is no indentation on the left. I.e. if you need to comment out an entire function or class, you must additionally press Enter at the top and bottom of the class/function.
It helped me.
Often in coding and templating I need to wrap a certain part of text. Is there any shortcut to wrap the current selection, for example:
Hello World
"Hello World"
Hello World
{{ trans 'Hello World' }}
Im using PhpStorm 7 for Mac and PC. I found something similiar, with: ctrl+alt+j you can wrap with a html-tag but nothing else. Also ctrl+alt+- comments the current selection according to the current file format(php, twig, html, ...)
I know this is a little late answer, but I hope anyone who looks this question get helped.
In PhpStorm, almost everything can be configured but a little tricky and takes some learning curve.
It's very common behaviour that select a word and type single quote (or double quote) to surround it.
Hello World
'Hello World'
"Hello World"
To enable this, tick on checkbox of Preferences -> IDE -> Editor -> Smart Keys -> Surround Selection on typing quote or brace.
Another way, you select something (word, condition) and press Cmd + Alt + T (on Mac) , Ctrl + Alt + T (on Windows). Available Surround With options dialog box will be displayed.
Update (for PhpStorm8)
For PhpStorm Version 8, tick on checkbox of Preferences -> Editor -> General -> Smart Keys -> Surround selection on typing quote or brace.
Update (for PhpStorm 2016)
For PhpStorm Version 2016, use Cmd + Alt + S (on Mac) or Ctrl + Alt + S (on Win) to go to Settings. Tick on checkbox of Settings -> Editor -> General -> Smart Keys -> Surround selection on typing quote or brace`.
As of 2015-02-26 (PhpStorm 8) go to:
File > Settings... > Editor > General > Smart Keys > Surround selection on typing quote or brace
How to create a live template to easily change Hello World into {{ trans 'Hello World' }}:
Select something (word, condition) and press Cmd + Alt + T (on Mac) , Ctrl + Alt + T (on Windows). Available Surround With options dialog box will be displayed.
Select Configure live templates.
On the right bar there are a "+" to add either a group or live template.
In Edit part choose "Abbreviation", so you could see it in a menu later.
In "Template text" add following: {{ trans '$SELECTION$' }}
Click ok to save changes.
After that select Hello World and use step 1 from above, select a rule with your "Abbreviation"
This is just a more detailed answer than #Steve.NayLinAung .
Credit goes to #LazyOne
On a Mac, it's
PhpStorm > Preferences > Editor > General > Smart Keys > Surround selection on typing quote or brace.
You can also press command+, to open the Preferences menu.
TextMate 1 had a preference called "Auto-pair characters (quotes etc.)" that would allow you to enable or disable the auto pairing functionality.
Is it possible to disable this feature in TextMate 2?
You can disable it for a given bundle as explained in this issue on GitHub.
Basically you have to edit an option file of the bundle and add smartTypingPairs = ( ); near the end of the file.
I don't know if this can be generalized using the .tm_properties files but you are welcome to try (and report your results).
There is also a user defaults key for this:
defaults write com.macromates.TextMate disableTypingPairs -bool YES
Automatic "Typing Pairs" is a TextMate 2 Hidden Setting
When you type an opening brace, parenthesis, quote character, or similar, TextMate will insert the closing character.
Disable via Terminal:
defaults write com.macromates.TextMate disableTypingPairs YES
A follow-up for Ruby coders. After disabling auto-pairing, you'll still find that typing # inside a double-quoted ("...") string expands to #{}. If you want to disable this:
"Bundles" menu -> "Edit Bundles..."
Select "Ruby" in the left column
Select "Other Actions" in the next column
Select "Embedded Code - #{...}" in the third column
Turn off the "Enable this item" checkbox in the drawer
Type Cmd+S to save the updated bundle
Now you can type "# without any auto-expansion/pairing. If you like typing # and having the first { appear but don't want the closing } added, then instead of disabling the item, just edit in the bottom pane to remove the trailing }:
#{${1:$TM_SELECTED_TEXT}
If you like selecting text within strings and typing # to have it enclosed in #{...} though, the above changed will make it quite awkward, so beware.
How I can search within a specific block of code or selection in IntelliJ IDEA?
I got used to using this feature in Eclipse. In Eclipse you can just double click on the beginning of a curly bracket, and it'll highlight the entire block of code. After which you could do Command+f
(Ctrl+f on Windows) to search ONLY in the highlighted block, or you could just highlight whatever you need and search just that block of code.
Go to Settings | Keymap, search for the Find... action in the Other group. This action should have the following description:
Find a string in active editor, shows
modal dialog
Assign a keyboard shortcut to this action (you need to make a copy of default keymap to modify it), for example Ctrl+Alt+Shift+F.
When in editor, select any block of text, then press this shortcut, a dialog will open with the Scope automatically set to Selected text:
To quickly select the method body while standing on the opening curly brace use Ctrl+W.
As of 2020, I'm able to perform find in selection on PhpStorm
Select the block of text and hit Cmd + F on MacOS / Ctrl + F on other platforms
On the find toolbar (that appears on top) there's an In Selection button; use that to limit search scope to the selected text only
Here's the link to my original answer on JetBrains support forums
I'm using
PhpStorm 2020.1.2
Build #PS-201.7846.90, built on June 3, 2020
First select some text and press ctrl+R to open the dialog, then check the "in selection" option :
In current version, 2020.2, default for Find In Selection is Ctrl+Alt+E.
On IntelliJ in Mac:
In a file select the specific block in which we want to find something
Press CMD + F
Press CTRL + OPTION + G
Notice that the cursor has automatically landed in the find toolbar's text field
Type in what is intended to be found
Press enter to move the cursor to the first occurrence.