Crystal multi line comment - comments

Are there any multi line comments in Crystal ? Such as Ruby does :
=begin
this is a
multiline
comment in Ruby
=end
This will simply give me an error in Crystal :
unexpected token: =

Crystal doesn't have multi-line comments. Simply prefix the block of lines you want to comment out with # single-line comments. Your editor should be able to do this for you.

Crystal allows multi-line comments by highlighting multiple lines and then using the shortcut Alt+M

Related

Is it possible to change ruby comment symbol?

So, to comment in ruby, you need the # symbol.
# this is some comments
Which is fine, but for multi-line comments, ruby has an ugly system.
=begin
comment line 1
comment line 2
=end
I have search around the internet and found nothing on the topic. I want to see if I am able to change that format to something better by defining my own commenting system. Such as:
/*
comment line 1
comment line 2
*/
I want to see if I can do something like
def /*
define comment logic
end
def */
define comment logic
end
Just something to that effect. I don't need to replace to current one, just want to see how I can define my own. I'm not looking to rewrite ruby. I just want to see if there is something simple that i can do whenever I write ruby. As an example, if I want to add a method to the String class, I can do
class String
def new_method
# some new functionality.
end
end
I want to see if I can do something like that for comments.
Nobody uses multi-line syntax. People do this instead:
# comment line 1
# comment line 2
Most editors have a shortcut that allows one to comment in multiple lines easily. You will get used to it!
A comment says "Ruby stops here, what follows is outside of Ruby". Therefore, it should be pretty obvious, that you cannot change what a comment is from inside Ruby.
But there's another problem with your proposed syntax: it is already valid Ruby. It's a multi-line Regexp literal. (Yes, it is semantically invalid, but it is a syntactically valid Regexp literal.)

PhpStorm Reformat Comments Automatically?

Is there any way for PhpStorm to automatically reformat all comments in my project? I've already changed the settings to use one-line comments but it doesn't seem to do anything when I run the code formatter.
For example, let's say I have the following comment:
/*
* Hello, I am a comment
*/
Is there any way for PhpStorm to auto-convert it to this:
// Hello, I am a comment
I'd also want it to work for multi-line comments i.e.:
/*
* Hello, I am a comment
* I'm on multiple lines
*/
Should become this:
// Hello, I am a comment
// I'm on multiple lines
Is it possible for PhpStorm to do this for my entire project automatically?
Just ended up doing a regex replace:
find: \/\*\n(.*)\* (.*)\n(.*)\*\/
replace: // $2
That worked for my first comment, the one with multiple lines I just changed manually.

Is there a way to delete all comments in a file using Notepad++?

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?
Edit: Stat-R's bookmark method has helped greatly, not only for removing comments but for conditionally removing lines in general.
For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //.
For the following code...
In NP++, you need to
Mark the lines that contains '//'. Make sure the bookmark option is enabled.
Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines
EDIT:
Another solution after #Chris Mirno 's suggestion is as follows:
Use regular expression. See the image below. It is self explanatory
To understand it better, refer to these
In the Find & Replace Dialog, put the following regex and adjust the search options as depicted.
/\*.*?\*/
Replace with: (empty)
Select Mode: Regular Expression AND .(dot) matches newline
This should remove all your C style comments spanned across lines.
Star-R and Chris Mirno Answer are also Correct and Good.
But For Line Comment:
//.*?(?=\r?$)
Explanation:
// will be the Starting Position
.*? Will be any character
(?=\r?$) will search to the end of the line (as it is required in line comment)
Note:
But Still check each of the line because for example if your code contains soap format like
//www.w3.org/2001/XMLSchema-instance\x2......");
it will capture this line because the starting is // and it goes to end of the line so watch out for this :)
Warning to all using Stat-R's solution:
This method will remove lines of code if formatted like this:
echo "hello"; //This comment will be detected
Following his method, the entire line will be removed.
Therefore make sure to go through and make these comments, their own line before doing this method.
I have had some luck running a macro for the above. Basically:
search for // (F3)
select to end of line (shift+end)
delete (delete)
Put // into the search dialog by just searching for it once. Then record the three steps in a macro, then play it back until EOF.
The first time I did it I had a problem, but then it worked, not sure what I did differently.
Anton Largiader's answer was the most reliable one, including complex inline comments.
However, it will leave many empty lines, including ones with empty characters (space, tabs...) so I would just add another step to make it almost perfect:
After running the macro, just do:
Edit > Line Operations > Remove Empty Lines
OR
Edit > Line Operations > Remove Empty Lines (Containing Blank Characters)
1st option is good if you wish to remove only really empty lines
2nd options will remove every empty line even containing space etc. so there will be no more actual spacing left between code blocks. 1st option might be the safest with some manual cleanup afterwards.
As someone suggested in another post, the simplest and most reliable is maybe to export the all text in .RTF format using Menu Plugin-->NppExport-->Export to RTF and then:
-Open the newly created file in Word
-Select any part of any comment
-On the top-right side of Word clic Select--> Select all texts with similar formatting
-Remove the selected comments all at once (del or cut if doesn't work)
To remove Powershell comments if someone find it handy:
Removing Comment in a Powershell using Notepad ++
To find just lines beginning with # (and not with # elsewhere in the line).
Notepad++ SEARCH Menu > Find
‘Mark‘ Tab – fill in as below.
Select ‘Mark All’ (clear all marks if used previously).
Regex ^[#}
enter image description here
SEARCH Menu > bookmark > Remove (or do anything on the list with
them)
Clear all marks to reset
You can select no comments just code by doing the following:
Regex ^[^#}
enter image description here
Enter ctrl+shift+K to remove comment

Visual Studio macro to find a string and delete matching lines

In my Visual Studio (2010 C#) solution, I need to delete all lines of code that contain a matching string pattern.
For example, I want to delete all lines that contain ".BackColor = System.Drawing.Color.Yellow;". The Find and Replace feature of Visual Studio isn't good enough, because you cannot tell it to wipe out the matching lines.
So I think I would need a macro for that. Any help is appreciated.
You can use the "Find and Replace" feature of Visual Studio to delete matching lines.
The key is to match the whole line including the end of line character as well. You can do this in wildcard or regular expression mode. In wildcard mode, begin the expression with * and end the expression with *\n. The asterisks will match any number of characters, and the \n will match the end of line character.
In your case, your find query would be "*.BackColor = System.Drawing.Color.Yellow;*\n". The replace field should then be left blank.
To enable wildcard mode, select 'Wildcards' in the 'Use:' field of the 'Find options' section of the 'Find and Replace' dialog.
With Visual Studio 2015, 2017, 2019, 2022 this worked for me. Open Search window, check the "use regular expressions" checkmark. Fill "find what" with
.*myCodeFragmentHere.*\r?\n
fill "replace" with an empty string.
Remove all regexp (brackets, dots) from the code fragment in your search expression.
I tend to create macros in VS by running the macro recorder then editing the resulting code.
So, manually search for the pattern, and press F3. Stop the macro then (or press the line-start key, select to end of line, press delete and then stop the macro).
Edit the macro, the command to delete a line is:
DTE.ActiveDocument.Selection.SelectLine()
DTE.ActiveDocument.Selection.Delete()
You can set the find text with FindText:
DTE.ActiveDocument.Selection.FindText(".BackColor = System.Drawing.Color.Yellow;", vsFindOptions.vsFindOptionsFromStart)
Building upon #HolgerJeromin's answer: instead of guessing the right indentation match (could be tabs could be spaces could be more or less), I prefer matching the beginning of the line using the ^\s* pattern.
For example, to remove all lines having a ProducesResponseType attribute, I use
^\s*\[ProducesResponseType.*\n
(works on Windows too using VS 2019).
For Visual Studio 2015 (in which there are no macros and no wildcards), I did the following:
Open Find and Replace (Ctrl+H)
Set to use Regular Expressions (Alt+E)
Set the Find box to
({line of code string})\r?\n({next line tabbing})
Leave the Replace box empty
Replace
Where-
{line of code string} = the line of code you wish to remove. Note you need to escape characters such as parenthesis and quotes with a backward slash ()
{next line tabbing} = the number of spaces preceding the next line of code (without this your line will be removed but the next line would have double the spaces before it
For example, to remove
DoSomething("hello");
From -
class A
{
void SomeMethod()
{
DoSomething("hello");
DoSomethingElse();
}
}
Replace the following
(DoSomething(\"hello\")\;)\r?\n({ })
I was trying to remove an attribute ([OperationContract] in my case) and none of the other answers worked for me. I finally got it to work by using the following:
\[OperationContract\]\r\n\t\t (Use Regular Expressions)

How do you do block comments in YAML?

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
How do I comment a block of lines in YAML?
YAML supports inline comments, but does not support block comments.
From Wikipedia:
Comments begin with the number sign ( # ), can start anywhere on a line, and continue until the end of the line
A comparison with JSON, also from Wikipedia:
The syntax differences are subtle and seldom arise in practice: JSON allows extended charactersets like UTF-32, YAML requires a space after separators like comma, equals, and colon while JSON does not, and some non-standard implementations of JSON extend the grammar to include Javascript's /* ... */ comments. Handling such edge cases may require light pre-processing of the JSON before parsing as in-line YAML.
# If you want to write
# a block-commented Haiku
# you'll need three pound signs
The specification only describes one way of marking comments:
An explicit comment is marked by a “#” indicator.
That's all. There aren't any block comments.
I am not trying to be smart about it, but if you use Sublime Text for your editor, the steps are:
Select the block
Cmd + / on Mac or Ctrl + / on Linux and Windows
Profit
I'd imagine that other editors have similar functionality too. Which one are you using? I'd be happy to do some digging.
In Vim you can do one of the following:
Comment all lines: :%s/^/#
Comment lines 10 - 15: :10,15s/^/#
Comment line 10 to current line: :10,.s/^/#
Comment line 10 to end: :10,$s/^/#
or using visual block:
Select a multiple-line column after entering visual block via Ctrl+v.
Press r followed by # to comment out the multiple-line block replacing the selection, or Shift+i#Esc to insert comment characters before the selection.
An alternative approach:
If
your YAML structure has well defined fields to be used by your app
AND you may freely add additional fields that won't mess up with your app
then
at any level you may add a new block text field named like "Description" or "Comment" or "Notes" or whatever
Example:
Instead of
# This comment
# is too long
use
Description: >
This comment
is too long
or
Comment: >
This comment is also too long
and newlines survive from parsing!
More advantages:
If the comments become large and complex and have a repeating pattern, you may promote them from plain text blocks to objects
Your app may -in the future- read or update those comments
One way to block commenting in YAML is by using a text editor like Notepad++ to add a # (comment) tag to multiple lines at once.
In Notepad++ you can do that using the "Block Comment" right-click option for selected text.
Emacs has comment-dwim (Do What I Mean) - just select the block and do a:
M-;
It's a toggle - use it to comment AND uncomment blocks.
If you don't have yaml-mode installed you will need to tell Emacs to use the hash character (#).
If you are using Eclipse with the YEdit plugin (an editor for .yaml files), you can comment-out multiple lines by:
selecting lines to be commented, and then
Ctrl + Shift + C
And to uncomment, follow the same steps.
For RubyMine users on Windows:
Open the file in the editor.
Select the block and press:
Ctrl + /,
And you will have the selected block starting with #.
Now if you want to uncomment the commented block, press the same key combination Ctrl + forward slash again.
In the Azure DevOps browser (pipeline YAML editor),
Ctrl + K + C Comment Block
Ctrl + K + U Uncomment Block
There also a 'Toggle Block Comment' option, but this did not work for me.
There are other 'weird' ways too: Right-click to see 'Command Palette' or F1
Then choose a cursor option.
Now it is just a matter of #.
Or even smarter [Ctrl + K] + [Ctrl + C]
In a .gitlab-ci.yml file, the following works:
To comment out a block (multiline): Select the whole block section >
Ctrl K C
To uncomment already commented out block (multiline): Select the
whole block section > Ctrl K U

Resources