Reputation: 41
I've encountered unexpected behavior in Visual Studio 2022. When you paste text containing a double quotation mark (e.g. ");
) to a text line that already has a double quotation mark on it, then Visual Studio will automatically add a backslash.
For example, if you have the code line:
string myVar = " Something
And if you want to paste ");
at the end of it, then it will produce:
string myVar= " Something \");
And this will trigger a syntax error of course.
When pasting the same text (");
) to a line without a double quotation mark on it, the paste works as expected:
string myVar = Something ");
Does anyone know how to avoid this?
Upvotes: 4
Views: 1000
Reputation: 185
Crazy annoying, isn't it? You can de-select the 'Fix text pasted into string literals' option in the Tools -> Options menu. Go to the Text Editor section and select the language you're working in (in this example, I'm using C#), then select "Advanced" and scroll down to the "Editor Help" section to find that option and de-select it. This should resolve your issue.
Here's a screenshot from a GitHub bug report about this feature, shared by Cyrus Najmabadi on 2024-02-01:
Upvotes: 7