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.
Related
How to single comment out selected text in a bulk? I have 100+ lines of text that have to be commented out, single line each but idk how to do it, you can only comment out in bulk multiple lines that are treated like one entity using /* text */, but I want to transform:
a
b
c
into:
--a
--b
--c
in a single command, anyone knows how to do it?
Highlight the lines and then use:
Ctrl+/
Ctrl+Shift+/ or
from the menu Source > Toggle Line Comments.
I want to select multiple lines and put a cursor at the beginning of each line. Sublime Text can do this with Ctrl-Shift-L
select multiple lines
ctrl + shift + L and then put cursor at beginning of each line
Press Crtl + Shift + Alt + Arrow up/down to select multiple lines in Visual Studio Code. Note that the selected lines will be in one column (if possible).
You can also mark some lines and then do this combination and you have all selected lines included.
Moreover you can press and hold Alt and click the lines you need. This way you can select multiple lines that are not neighbours or in the same column.
To do exactly what Ctrl-Shift-L does in Sublime Text, you must do:
On Windows:
Select the lines.
Alt-Shift-I (will add multiple cursors)
Shift-Home (will go at the beginning of each line and be selected)
On Mac :
Select the lines.
alt-shift-I (will add multiple cursors)
cmd-shift-←
(will go at the beginning of each line and be selected)
More information in this answer.
Put cursor at beginning of first line
Ctrl-Shift-Alt-Arrow down/up will put a cursor at the beginning of the following/preceding lines
Ctrl-I will select those lines with the cursor at the beginning of each line.
NOTE : On my vscode the cursors look like they might be shifted down one line but they actually are not - the are in the right place. If you start typing, it works but you have to hit Enter when you are done to get back separate lines. It is a little quirky but works as you would expect.
EDIT (using a hint from #Maxime's answer)
Select your test first.
Alt-Shift-I : puts cursors at the end of each of those lines but text unselected (I as in island not a lowercase L)
Function-Home : put cursors at beginning of each line.
Ctrl-I : selects all lines.
Important: read the NOTE above.
--------------------- v1.43 see How to put the cursor at the end of all selected lines in Visual Studio Code? with column selection mode it is easy to put the cursor at the beginning or end of lines selected by dragging.
You can hold alt and click the places you need with the mouse. This way you can select rows that aren't related, like row 10,15,18. Also you can select at different places in the same row.
I hope this helps someone, but there is a setting in VSCode called Editor: Multi Cursor Modifier which may do what OP is asking:
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.
Is there a way to temporary comment out some of code in SQLiteStudio? I have to add -- or /* ... */ each time and remove them manually. It will be greate if we can trigger comment using a button or shortcut like Ctrl-/. How do you tackle this problem when using SQLiteStudio?
(SQLiteStudio 3.0.7 on Windows 7)
Now it is available via these notations:
-- for one line comments
/*
for several line comments
*/
Edit:
Ctrl + / : comments the line which cursor is on it, also this hot key adds several line comment notation to the start and end point of selected area.
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