I am having the opposite problem than this question: In a SASS .scss file, I want comments command (ctrl/⌘ + /, ctrl/⌘ + K ctrl/⌘ + C) to default to //, and use the Block comment /* ... */ only when using the block comment (shift+alt+A).
I have been unable to find a way to change this setting, via the user settings or even a plugin. Is it possible? Is my google-fu just bad?
A very belated answer, but you can amend the language-configuration.json file for the language in question. More here: https://code.visualstudio.com/api/language-extensions/language-configuration-guide.
Related
Say I have code like this
some_line_of_code
some_line_of_code
/* some comment about code */
some_line_of_code
some_line_of_code
and i would like to comment out a whole block like this
/*
some_line_of_code
some_line_of_code
/* some comment about code */
some_line_of_code
some_line_of_code
*/
As you can see even SO code parser will not consider last 2 lines of code comments. Is it possible to comment out blocks of code that contain comments?
edit :
To clarify, I need this to be able to comment out large sections of code to check if a function I changed can compile in a package that otherwise can't be compiled until all changes have been done.
In SQL Developer, I highlight all lines of PL/SQL that I want commented and use Ctrl + /.
Obviously, you would like a way to comment and uncomment multiple lines quickly. This will put -- in front of each line you have highlighted. Do the same command to uncomment.
you can assign a function key through Tools > Preferences > Key Configuration (Edit / Selection / Comment Lines).
Shortcut to comment a line:
Command + Option + /
(in Mac)
As was stated by #Acroneos, there is no way. This is common behaviour of most programming languages. Comments as well as oher tokens are recognized by lexers. And lexers work with context-free grammars. i.e. lexes usually can recognize only reqular expressions.
You can still use C/C++ approach (#if 0/#endif). See Conditional compilation. But it does not look "so nice".
begin
something1;
$if false $then
something2;
$endif;
endl;
you can use --
so this code :
some_line_of_code
some_line_of_code
-- some comment about code
some_line_of_code
some_line_of_code
will be :
--some_line_of_code
--some_line_of_code
---- some comment about code
--some_line_of_code
--some_line_of_code
No, because everything between first delimiter until the next last delimiter will be recognized as comment (=not processed by compiler). Thats how multiline-comments work: If first delimiter (/ * ) is recognized, compiler will ignore anything until the very next last delimiter ( * /) is recognized. Now as you know this, you should be able to understand, why your second / * will never be recognized as a comment-delimiter by the compiler.
However, you can mark comments with special characters or concatenations within the multiline-comment-sector to line out comments into different sections.
in sql developer ; default shortcut is : ctrl + shift + c
In Sql Developer,You can use the following commands...
For Commenting Sql Statements...
ctl and / keys
For un-commenting Sql Statements...
ctl and / keys again
Additionally, to format sql statement
ctl and F7
I have a JavaScript line similar to:
var a = (b / 2) + (c / 2);
In Dreamweaver, it highlights this segment as a comment and treats it like this:
var a = (b /* 2 ) + (c */ 2);
It's incorrect syntax highlighting and very annoying. Where do I find syntax highlighting definitions and how do I modify them to correct this?
You can delete/modify the regex definition yourself by finding CodeColoring.xml in your Dreamweaver's configuration path. For CS6 in Windows 7, the default is:
C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration\
You will then need to find the JavaScript scheme:
<scheme MMString:name="JavaScript/scheme/name" id="JavaScript" ...>
And within it, you'll find the regexp definition:
<regexp name="RegExp" id="CodeColor_JavascriptRegexp" delimiter="/" escape="\\">
<searchPattern><![CDATA[/\e+\\/]]></searchPattern>
</regexp>
This can probably be refined, but I don't use regular expressions in most scenarios so I just deleted this segment. Restart DW, and voila.
If you want to refine the definition, StackOverflow seems to have its regex highlighting down:
var regex = /a+b/;
var number = (window.innerWidth / window.innerHeight) / 2;
This article explains how to do it:
Modifying Dreamweaver’s syntax highlighting
http://realworldz.wordpress.com/2007/10/04/modifying-dreamweavers-syntax-highlighting/
It gives an example of how to add syntax highlighting to the keyword new for VBScript:
Close Dreamweaver if it’s already open.
Go to C:\Documents and Settings\<YOUR USERNAME>\Application Data\Macromedia\Dreamweaver 8\Configuration\CodeColoring
Open the “ASP VBScript.xml” file in Notepad.
Look for the tags and after the one for “Mod”, add in a new one called for the keyword “New” like this; <keyword>New</keyword>
I have looked everywhere and I agree with the answer from this previous question: Dreamweaver CS5 code hinting
There is just not that much control over syntax highlighting. You can use the method described by Robert's answer here to add more reserved words and such. But editing that file does not apply to changing how Dreamweaver handles highlighting of constants and operators.
Here is a reasonable way to change the way you write you code so that you syntax will still be highlighted in examples like this.
<script>
var a =
(b/2) //Because the forward slashes are not on the same line,
+(c/2); //Dreamweaver will not stop highlighting the numbers
//and operators
document.write(a);
</script>
Note: in this specific example your code can also be simplified to var a = (b+c)/2;
Since the characters /([{;,=!|&~^<>+-*%?:} can't be followed by a division sign, this is what I came up with:
<searchPattern><![CDATA[/\s+/\e+\\/]]></searchPattern>
(this one must have at least one whitespace character to avoid conflicts with end-of-line comments)
<searchPattern><![CDATA[(\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[[\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[{\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[;\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[,\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[=\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[!\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[|\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[&\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[~\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[^\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[<\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[>\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[+\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[-\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[*\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[%\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[?\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[:\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[}\s*/\e+\\/]]></searchPattern>
For scenarios like if (x) /foo/.exec('bar'), just put the RegExp in parenthesis to format it properly. The only other ill effect is that the preceding character will just be formatted as regular text (not bold or colored).
In C#, is there a reason why multi-line /* */ comments can't overlap? This also applies to HTML (and I'm sure lots of other languages) too.
e.g.
/*
int a = SomeFunction();
/* int i = 0; */
int b = SomeFunction();
*/
won't compile.
When writing code I often want to quickly check the logic, and isolate certain parts by removing a section using multi-line comments, but then have to go through the code block replacing all multi-line comments with single line ones //.
I don't like using single line comments to comment-out code blocks (even though Visual Studio provides shortcuts to do this) as these then affect text comments when it comes to removing all comments in the block using the shortcut.
Is there a reason why the multi-line comment cannot mean: 'ignore everything between here'?
I'm afraid this is the way how it's designed.
I think you should use single line comments as much as possible. It's also much clearer when you are viewing the history of a file in source control. If you commented an entire method with /* */ then only two lines will appear changed, otherwise the entire method will have been changed (// added).
I have a common issue when working with code in the IDE:
string.Concat("foo", "bar");
and I need to change it to:
string.Concat("bar", "foo");
Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.
Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.
<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...
I had a lot of code with this function:
SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...
And I needed to swap only the first two parameters;
I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:
Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1
This question already has answers here:
How can I reverse code around an equal sign in Visual Studio?
(6 answers)
Closed 4 years ago.
I have a bunch of assignment operations in Visual Studio, and I want to reverse them:
i.e
i = j;
would become
j = i;
i.e. replacing everything before the equals with what's after the equals, and vice versa
Is there any easy way to do this, say something in the regular expression engine?
Select the lines you want to swap, Ctrl+H, then replace:
{:i}:b*=:b*{:i};
with:
\2 = \1;
with "Look in:" set to "Selection"
That only handles C/C++ style identifiers, though (via the ":i"). Replace that with:
{.*}:b*=:b*{.*};
to replace anything on either side of the "=".
Also, since you mentioned in a comment you use ReSharper, you can just highlight the "=", Alt+Enter, and "Reverse assignment".
Just a slight improvement on Chris's answer...
Ctrl+H, then replace:
{:b*}{[^:b]*}:b*=:b*{[^:b]*}:b*;
with:
\1\3 = \2;
(better handling of whitespace, esp. at beginning of line)
EDIT:
For Visual Studio 2012 and higher (I tried it on 2015):
Replace
(\s*)([^\s]+)\s*=\s*([^\s]+)\s*;
with:
$1$3 = $2;
In Visual Studio 2015+ after selecting code block press Ctrl + H (Find & Replace window) and check "Use Regular Expression" option, then:
Find: (\w+.\w+) = (\w+);
Replace: $2 = $1;
For example:
entity.CreateDate = CreateDate;
changes to:
CreateDate = entity.CreateDate;
Thank you #Nagesh and Revious, mentioned details added.
The robust way to do this is to use a refactoring tool. They know the syntax of the language, so they understand the concept of "assignment statement" and can correctly select the entire expression on either side of the assignment operator rather than be limited to a single identifier, which is what I think all the regular expressions so far have covered. Refactoring tools treat your code as structured code instead of just text. I found mention two Visual Studio add-ins that can do it:
ReSharper
MZ-Tools
(Inverting assignment isn't technically refactoring since it changes the behavior of the program, but most refactoring tools extend the meaning to include other generic code modifications like that.)
Please see this question: Is there a method to swap the left and right hand sides of a set of expressions in Visual Studio?
My answer to that question has a macro that you can use to swap the assignments for a block of code.
I've improved the expression a little.
Replace
(\t+)(\s*)(\S*) = (\S*);
with
$1$2$4 = $3;
The reason is, it will look for lines starting with tab (\t). It will skip the lines starting with definition. E.g.:
TestClass tc = new TestClass();
int a = 75;
int b = 76;
int c = 77;
a = tc.a;
b = tc.b;
a = tc.c;
Would ignore the int a, int b and int c and swap only the assignments.
what about replace all (CTRL-H)
you can replace for example "i = j;" by "j = i;"
you can use regular expressions in that dialog. I'm not so sure about how you should pop-up help about them however. In that dialog, press F1, then search that page for more information on regular expressions.
I like this dialog because it allows you to go through each replacement. Because the chance of breaking something is high, I think this is a more secure solution
You can do search and replace with regular expressions in Visual Studio, but it would be safer to just do a normal search and replace for each assignment you want to change rather than a bulk change.
Unfortunatly I don't have Visual Studio, so I can't try in the target environment, but if it uses standard regexps, you could probably do it like this:
Search for "(:Al) = (:Al);", and replace with "\2 = \1". (\1 and \2 are references to the first and second capture groups, in this case the parenthesises around the \w:s)
EDIT
Ok, not \w... But according to MSDN, we can instead use :Al. Edited above to use that instead.
Also, from the MSDN page I gather that it should work, as the references seem to work as usual.