NetBeans commenting - netbeans

I'm using the popular IDE NetBeans and I have problems commenting code on the same line. For example, let's say we have the following line:
<h1> Some text </h1> comment for h1
I would like to comment the part "comment for h1" through a key combination or some other means but without having to type manually and without transferring the comment string to the next line. I usually use ctrl+/ but this key combination comments the whole line, which is not what I want.

Why not Select & Replace all such occurences.
You can use Ctrl + Shift + H and enter the text which you want to replace.
Add the text (say comment for h1) to be commented in the field Containing Text, and replace that text with //comment for h1 in the Replace With field.
Then it will show you all the matches which you want to comment. You can select the desired places where you want to place comment before the text.
Finally, click on Replace ? Matches button. Voila, that's it...

You can always create your own keyboard shortcut, see how in this link.
Then you can customize your keyboard to replace your highlighted text with the same text with /* */ , // , <!-- --> or any others before/surrounding the text.
Example:
<h1> Some text </h1> comment for h1
Highlight the text you need to comment (comment for h1).
Use your customixed shortcut and:
<h1> Some text </h1> /*comment for h1*/
I haven't tested this, please tell me your feedback ;)

I've decided to do this by recording 2 macros and assigning shortcuts to them:
ctrl + shift + A for the html comment <!-- -->
ctrl + shift + \ for the php comment /* */.
Both macros position the mouse cursor in the middle of the comment section so it is convenient to enter a comment. This doesn't work with an existing comment.

select the texe and use Ctrl+Shift+C

Related

Keyboard Shortcut to Surround Selection with HTML Tag

Desired Steps:
Highlight (select) HTML/text, e.g. really
Press keyboard shortcut
Highlighted text becomes <b>really</b>
How to?
In a Javadoc comment you can just select the text which you want to wrap in a <b> tag and press CTRL+Space. Select the <b> template, press Enter and the selected text gets surrounded as expected. There are pre-defined templates for <b>, <code>, <i> and <pre>. You can define your own templates here: Java -> Editor -> Templates.
You're looking for Quick Fix/Quick Assist: Ctrl/Cmd+1. Then start typing the tag name.

How to edit all lines in Visual Studio Code

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:
abcde
cdeab
deabc
eabcd
And I want all of the lines to look like this:
'abcde'
'cdeab'
'deabc'
'eabcd'
In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!
You could edit and replace with a regex:
Find (Ctrl+F):
^(.+)$
Replace:
'$1'
This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.
If every line may or may not have a space before the content, and you want every line to have a space, try this:
Find:
^ ?(.+)$
Replace (notice the space before the first quote):
'$1'
Here is an easy way to do this:
Ctrl+A to select all or select your desired text.
Shift+Alt+I to put a cursor at the end of each line.
Type your ' (or whatever you want at the end).
Home will move all your cursors to the beginning of the lines.
Type your ' (or whatever you want at the beginning of all the lines).
You can use the Alt + Shift shortcut.
First press Alt + Shift then click the mouse button on the first line.
Go to the last line, and then do the same.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Do the same on the other side too.
Use Toggle Multi curosr Modified from action pane.
Select the cursor points with ctrl + <Mouse click> , you can modify everything simultaneously.
This will require lots of manual efforts if lines are more
You can use Find and Replace.
Besides, paste to Excel and using a function to add character '.
The first thing that came to my mind - replace abcde with 'abcde' line by using option Find and Replace option. I'm pretty sure Visual Studio Code has something similar to that.
You can use the Shift +Alt shortcut for windows and for Mac use Shift + Option
First press Alt + Shift/Shift + Option then click the mouse button on the first line.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Place Cursor where you want to insert/delete text.
Goto Selection Menu and choose Column Selection Mode
Scroll to the bottom of the data and shift + click in the last line where you placed the first cursor.
Perform action (add/delete whatevs)
Repeat for whatever other areas you want to change.
v: 1.74.3
1- You can use the Ctrl + H shortcut (menu Edit → Replace)
Enter abcde in Find Control.
Enter 'abcde' in Replace Control.
Then press Ctrl + Alt + Enter.

Sublime Text 2 wrapping selection in tag

In ST2, highlighting some text and pressing alt + shift + w (on Windows) will wrap the current selection in <p></p> tags. But is there a way to specify which tag to wrap with? Because maybe I want to wrap in a span, or a div instead.
Using Emmet, place the cursor in the tag you want to wrap and press ctrl + w (for MacOS) or Alt+Shift+W (for Windows), a box will pop up to enter the type of tag you want to wrap with.
Single line
If you want to convert this
Lorem ipsum dolor sit amet.
to this
<div>Lorem ipsum dolor sit amet.</div>
do this:
Select the text, or press CTRL + L (it will select the current line)
Press ALT + SHIFT + W
Type the desired tag (it will overwrite the default p tag)
Multiple lines
If you want to convert this
Item 1
Item 2
Item 3
to this
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
do this:
Select the text, or press CTRL + L multiple times
Press CTRL + SHIFT + L (it will make one selection per line)
Press ALT + SHIFT + W
Type the desired tag (it will overwrite the default p tag)
You can also select the text using SHIFT + MOUSE RIGHT BUTTON, and in this case you can skip the second step.
Using Emmet
If you want to convert this
Item 1
Item 2
Item 3
to this
<nav>
<ul class="nav">
<li class="nav-item1">Item 1</li>
<li class="nav-item2">Item 2</li>
<li class="nav-item3">Item 3</li>
</ul>
</nav>
do this:
Select the text
Press SHIFT + CTRL + G (wrap with abbreviation)
Type nav>ul.nav>li.nav-item$*>a
Note for Mac users:
ALT + SHIFT + W = CTRL + SHIFT + W
CTRL + SHIFT + L = CMD + SHIFT + L
The answers are all good. Here is where key bindings are for customizing:
In Preference: Key Bindings - Default:
{
"keys": ["ctrl+shift+w"], "command": "insert_snippet",
"args": { "name": "Packages/XML/long-tag.sublime-snippet" }
}
If you have Emmet, the emmet version is
{ "keys": ["super+shift+w"], "command": "wrap_as_you_type"}
Edit them in Preferences: Key Bindings - User to your liking,
Create a custom snippet, for example, to insert a span tag. Go to the app menu: Tools > New Snippet ..., and copy to the window the snippet below:
<snippet>
<content><![CDATA[
<span style="color:#0000FF">$SELECTION$1</span>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>span</tabTrigger>
<description>HTML - span - color - blue</description>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.html</scope>
</snippet>
... then save the snippet to file with e.g. html-span--color name and bind that snippet to a key combination in Preferences > Key Bindings-User, creating a new key entry, for example:
{ "keys": ["alt+shift+c"], "command": "insert_snippet", "args": { "name": "Packages/User/html-span--color.sublime-snippet" } }
It is supposed that a location of the snippet is Packages/User/ directory.
Now select any text that you need to wrap in the span tag and press Alt+Shift+c or type 'span', press Tab, a cursor will be set to required position within the tag, just type your text.
I have successfully tested the snippet and key binding with Sublime Text 3 in Ubuntu Linux.
to make your life easy while you are in Sublime text3:
type any of these(p, h1, div, header, footer, title...) and hit Tab
for example if you want div Just type div and hit Tab
in ST2 type a tag without brackets and hit Tab. It will automatically give you open and closed tag
This system of inserting snippets is very cumbersome compared to the mechanism provided in Dreamweaver. In that case you build a snippet of any kind. It is stored in an in-RAM library and displayed in a directory-style structure. You declare whether the snippet is of type INSERT (at cursor position), or of type SPAN (span selected text). In the first case the entire snippet is inserted. In the second case the snippet is created with a "before" part and and an "after" part. Typically the "after" part is just the closing tag. To use INSERT HERE mode, you position the cursor, and double-click on the snippet in the library and it inserts it at cursor position. To use SPAN SELECTED TEXT mode, highlight the text you want, and double-click the snippet in the library. The selected text is surrounded by the "before" and "after" parts of the snippet.
This is very intuitive, easy to use, and enables the user to build unlimited kinds of snippets which can span selected text.
WOULD SOME VERY SMART PROGRAMMER PLEASE BUILD AN EXTENSION LIKE THIS FOR SUBLIME 3 ?
Note: In comparison, Bracket Highlighter is a Sublime plugin with a wrapping function that would seem to have such functionality, but on close inspection it is way too cumbersome to use if you want to build an efficient snippet library on-the-fly.
Thanks,
Peter Rosti

How can I do group commenting without commenting each line in MATLAB?

How can I comment a group of lines without commenting each line?
I.e., like in C:
/*
printf("hello");
printf("there");
*/
In MATLAB, the only way I know to do this is to comment each line:
%disp('hello')
%disp('there')
I have a 100 lines to comment out, and I would prefer to group comment it like in C.
Can I comment a block of lines in an MATLAB file using /* ... */ as I can in C?:
%{
...
Block of COMMENTS HERE
...
...
%}
%CODE GOES HERE
plot(1:10)
MATLAB v7+:
%{
...code to be commented
%}
Use the editor:
Select all the lines, and then choose toggle comment or something in the menu. It's there.
Or just select the group of lines you want to comment, and then use keystroke Ctrl + / (forward slash)'.
And voila, it will comment each line in the selected block with % as one would do individually.
To undo, I tried, but I don't know what key stroke can work.
Select all lines and then do:
For commenting:
From the Text menu → Comment
For uncommenting:
From the Text menu → Uncomment
You can use keyboard shortcuts:
To comment multiple lines: Ctrl + R
To uncomment multiple lines: Ctrl + T
It works perfect in MATLAB 2016.

Eclipse-like comment formatting in IntelliJ IDEA?

In Eclipse, I can format comments by selecting them and pressing Shift + Ctrl + F. For example, when I select a method comment like this:
/**
* This method
* does some stuff.
*/
and press Shift + Ctrl + F, Eclipse automatically wraps it:
/**
* This method does some stuff.
*/
Is there anything comparable to this in IDEA?
EDIT: To clarify, I'm looking for comment formatting that also breaks lines that are too long into multiple lines.
The closest thing that you can get is Edit | Join Lines (Ctrl+Shift+J). You have to select the lines you want to join first.
To wrap long comments enable Settings | Code Style | JavaDoc | Wrap at right margin.
For Javadoc comments, you want to make sure the "Wrap at right margin" setting is checked. See Code Style > JavaDoc, under "Other". However, this setting only seems to take effect when you reformat the whole file, since a reformat of just the Javadoc (i.e., select the Javadoc, then do a Code (menu) > Reformat Code... or CtrlAltL) that exceeds the right margin doesn't force it to wrap. If I reformat the entire file, then it wraps at the margin as expected.
This seems like a bug (though one that doesn't seem to have been reported), since if you have to set the "Ensure right margin is not exceeded" checked, then selecting the Javadoc text and doing a reformat code does indeed wrap the lines. This setting is in Settings > Code Style > Wrapping and Braces. You can also do a search in the Settings dialog for "ensure right margin".
You'll still have to manually join the lines using CtrlShiftJ
This might be worthy of an improvement request to JetBrains.
Existing comment will be reformatted when you do "Reformat Code" (⌥⌘L in Mac).
#kghastie uncovered the key.
Steps:
Set the Code Style > Java > JavaDoc > Wrap at right margin setting.
Select the full lines of the entire JavaDoc comment.
Reformat Code (Ctrl-Alt-L or ⌥⌘L).
Lesser alternative:
Set the Code Style > Java > JavaDoc > Wrap at right margin setting and the Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded setting.
Select some text within a JavaDoc comment.
Join Lines (Ctrl-Shift-J) followed by reformat Code (Ctrl-Alt-L or ⌥⌘L).
Beware: This will leave all the selected lines joined even where you had paragraph breaks (<p/> or \n\n).
The JetBrains plugin Wrap to Column is made for this:
From the overview:
Wraps text to the specified column width. Similar to the Emacs command 'Fill Paragraph' and Vim's gq (format lines) command. This is a replacement for the native Intellij Fill Paragraph command, which doesn't work quite how I need it to.
This plugin provies two IDE actions:
Wrap Line to Column: Wraps selected text or the current line if no text is selected. This is useful for IdeaVim users who wish to pair the command with motions like vip (select current paragraph).
Wrap Paragraph to Column: Wraps the paragraph (multiple lines) in which the cursor appears. No selection is needed, and will be ignored.
I'm using IntelliJ 14 on a Mac, which has a Fill Paragraph command. Access it via the awesome universal Command-Shift-A action search feature. Works like a charm!
This is a hack, not a really good solution, but if you have a block of code that you want formatted like this and it's in serious need of auto format, because it's going over the 80 line max, or it's just unreadable...
You can just put if ("foo" == "bar") { on top of whatever you want formatted, and then and the} at the bottom of the if statement, to close it, and voila, your code should auto-indent, auto format, etc... Then take it out, highlight all of what you just formatted and press SHIFT+TAB to move it back 4 spaces and remove the dummy if statement