Turn off automatic quote insertion in Visual Studio 2010 - visual-studio

I am editing a huge number of legacy ASP pages that have been converted over to C#. One problem is that the HTML attributes need to be adjusted to correct some double quote problems.
My problem is that when I add a double quote VS dutifully inserts the closing quote in the wrong place. I then need to go an delete that quote and enter the closing quote. I also have to watch that when I insert the closing quote it does not throw in another extra quote.
I googled for a solution, I am sure it is easy to turn off. But I could not find the right keywords to suss it out.

There are 2 options I'm aware of which control the insertion of the double quotes for ASPX pages.
Tools -> Options
Text Editor -> HTML -> Formatting
Under the Automatic Formatting Options try toggling the following options
I have both of these disabled and don't see the issue you're describing.

Related

How to removing annoying auto selection in VS Code

VS Code automatically selects somethings sometimes not only strings inside quotes but also language keywords sometimes. It usually after automatically closing parentheses or after an IntelliSense auto-completion.
This is very much annoying because it prevents further autocompletion when the text gets selected automatically autocomplete dont work.How can I solve this

Smart indent effect on completion (intelliSense) sessions

I am writing a Visual Studio extension which provides intelliSense for a certain content type.
The problem that I am facing now is the effect of "Auto Indent" that Visual Studio provides on empty lines when user types a character.
Here a completion session started on an empty line (over virtual spaces):
Notice the tab symbols on the other lines and no tab on the line with caret on it.
Now when use starts typing, VS automatically and correctly adds necessary tab characters to the line:
Now the problem is those Added tabs apparently become part of the user input and as a result CurrentSession.SelectedCompletionSet.SelectBestMatch() or Filter() method cannot find the current item which starts with "C" here (thinking user has typed \t\tC instead).
If I start the session on anywhere else which does not require auto indent everything works fine.
Any idea?
Edit (more information): I used a code flow very similar to:
Ook here
vsLua here
vsClojure here
In Lua and Clojure you wouldn't face this problem because they never provide intelliSense on virtual spaces (meaning they always start after a certain set of characters) and if you start after a character virtual spaces are already turned into real spaces.
Ook on the other had has the same problem.
Revised Answer:
Ah, I see. I interpreted your question thinking that you were referring to completion triggering via typing, not from the explicit command. If you enable "show whitespace" for the C# editor, you can see what we do here: when you trigger the "show completion" command, we explicitly realize the whitespace so you're no longer floating around in virtual space. You should probably do this as well. (Alternatively, you could detect the scenario and fix it up on the first typing by adjusting your ApplicableTo span, but that's probably not worth the trouble.)
You can get the whitespace that should be inserted from IEditorOperations. So MEF import an IEditorOperationsFactoryService, and then do:
var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
var whitespace = editorOperations.GetWhitespaceForVirtualSpace(textView.Caret.Position.VirtualBufferPosition);
if (whitespace.Length != 0)
{
textView.TextBuffer.Insert(textView.Caret.Position.BufferPosition, whitespace);
}
(Funny aside: as I answered this, I was curious to see how we handled this in the Roslyn C# and VB editors. The answer was "not", but filtering still worked by pure luck later in the code.)
Original Answer:
I suspect by your description of the problem that you are implementing your completion like this: you know a character is about to be typed (either via a keyboard filter or IOleCommandTarget) and you trigger an ICompletionSession, where the tracking span is an empty span on the current caret position.
The best approach to fixing this is to not trigger the session before the key is pressed and goes into the editor, but rather after it. This is what we do in the Roslyn implementation for C# and VB completion. Then, when you are in your AugmentCompletionSession call and creating your CompletionSet, compute the "applicable to" span which consists of the non-whitespace characters around your caret. The easiest way to compute this might just be to call GetWordExtent from the text structure navigator.
This allows for other scenarios to work right. Consider scenarios where the user types C, presses escape, and then continues to type your identifier. If you want to trigger completion again, you'd have to do the math to ensure that the "C" is counted as part of your span anyways.

How to change the highlight color for matched braces in VS2010

I need to change the highlight color for the matched braces in VS2010.
I have tried the following setting but it doesn't work at all.
Any suggestion is welcome.
Thank you
From Microsoft
...There are two Fonts and Colors options for brace matching: "Brace
matching (Highlight)" and "Brace matching (Rectangle)". Not all
languages use both settings. Each language implements its own brace
matching functionality, which can lead to inconsistencies in which
options are used in which language. For example, C#, HTML, CSS, and a
few others do not use the "Brace matching (Highlight)" option at all,
which is why it doesn't do anything when you change it in those file
types. However, "Brace matching (Rectangle)" should still work for C#,
HTML, and CSS, which it sounds like is consistent with your
experience. Some other languages will have the reverse behavior, i.e.
"Brace matching (Rectangle)" will do nothing but "Brace matching
(Highlight)" will work...
Not a good answer, but that's where VS2010 stands right now. Incidentally, when I changed
"Brace Matching (Rectangle)" Background color, it works for me in C++ and C#, if I have my cursor immediately left of an open brace or immediately right of a closing brace.
Good luck.
(tools) (options)
under (environment) (fonts and colors)
show settings for (text editor)
under (display options) there are two brace matching entires
(Brace Matching Highlight) is the one that you want.
Change it, maybe restart vs 2010 for good luck.
I use Visual Assist X for that task. After setting up visual assist for Visual Studio, you can change the bracer match and mismatch color under the display tab in the Visual Assist options menu.
Change Highlighted Reference in Item background dropdown
Watch it, if you use ReSharper, these settings will have no effect.
You first have to enable the Fonts and Colors in the newest ReSharper version.

how to enable matching braces option in VS2010

now i am using vs2010 trail version.
i want to see the matching braces if there are multiple braces. the opening brace and the closing brace must be highlight.. how to achieve this?
Thank you,
Mihir
The link above should give you all default key mappings.
Another useful link is: Pre-defined keyboard shortcuts
I'd just like to mention a couple that I find very useful:
To jump back and forth between matching braces, you can put your cursor on either brace, and then push Ctrl-]
And also Ctrl-M Ctrl-L toggles all outlining in the current file, and Ctrl-M Ctrl-M toggles the current region
from msdn: http://msdn.microsoft.com/en-us/library/be94e8aw%28v=vs.80%29.aspx
outlines all the options and how to set them up
for javascript: Brace highlighting in Visual Studio for Javascript?

Multiline Find & Replace in Visual Studio

Can it be done? We're using VS2005, VS2008, and VS2010.
I don't mean regular expressions—which have their place—but plain old text find and replace. I know we can do it (at a pinch) with regular expressions using the \n tag, but we prefer not to get tangled up in regex escape characters, plus there's a readability issue.
If it can't be done, what plain and simple (free) alternative are people using? That doesn't involve knocking up our own macro.
I finally found it...
There isn't any need to download and load any external macro.
It’s working in Visual Studio 2008 with in-built macro at least. :)
Steps:
Select text you want to find.
Press Alt + F8 or open "Tools -> Macros -> Macro Explorer"
Double click Sample → Utilities → FindLine. (It will open the Find box with your selection loaded in the "Find" field. Don't worry about truncated text shown in the "Find" field. Trust me, the field has it all... The Microsoft way of showing it may be... :) )
Click on the "Quick Replace" button in the "Find And Replace" dialog box. Enter your replace with text.
And click any of three buttons as per your requirement...and it’s done. :)
Hurray... it’s working. It may not be a straightforward way to do it, but you know with Microsoft. Nothing is straightforward and easy.. :)
This works today in Visual Studio 2012:
fooPatternToStart.*(.*\n)+?.*barPatternToEnd
See how the (.*\n)+? part does the match across multiple lines, non-greedy.
fooPatternToStart is some regex pattern on your start line, while barPatternToEnd is your pattern to find on another line below, possibly many lines below...
Example found here.
Simple and effective :)
Note: before VS2012, the pattern that worked was: fooPatternToStart.(.\n)+#.*barPatternToEnd
You can search for multiline expressions by clicking on the "Use Regular Expressions" checkbox in the "Find and Replace" dialog. Line breaks are then indicated by \n.
I use this:
Visual Studio Gallery Multiline Search and Replace
It’s provided by Microsoft only. Please check Multiline Search and Replace.
It uses regular expression only. But for those who don't know regex, it is better to use it.
You could also open the files with UltraEdit which fully supports MultiLine replace.
You can use the trial version if you only intend to use it once.
Regarding the comment of Andrew Corkery:
If you like to specify a multi-line replacement string as well, edit the macro code and set the replacement text as shown below.
This will allow you to "fine-tune" your replacement with just the small modifications needed.
Sub FindLine()
Dim textSelection As TextSelection
textSelection = DTE.ActiveDocument.Selection
textSelection.CharLeft(True)
DTE.ExecuteCommand("Edit.Find")
DTE.Find.FindWhat = textSelection.Text
' Also preset replacement text with current selection
DTE.Find.ReplaceWith = textSelection.Text
End Sub
The latest version (as of this posting) of Notepad++ does multi-line find/replace. With no macro support in Visual Studio any more, this is relevant now.

Resources