Is there a keyboard command in Visual Studio 2010 for exiting the current XML Comment tag? - visual-studio-2010

I love typing codes in my comment as much as the next developer, but one thing that commonly trips me up is when I'm trying to use inline tags (such as <c>ClassName</c>) Visual Studio will helpfully add the closing tag (</c>) the moment I type the closing angle brace (>) on the opening tag. This makes it annoying to smoothly keep typing my thoughts because I must move the cursor to after the closing XML tag before I can continue to type.
ControlRight Arrow allows you to move the cursor to the next 'word' but requires you to do the command three times to get to after the closing XML tag. Is there a better way to move the cursor quickly to where I need it?

Related

Visual studio Paste without moving cursor to the end

Is it possible to paste some string in visual studio via some shortcut or other extension to keep the cursor where it is after the paste?
This way if I add multiple words of string I will not have to go with the cursor back to the location via ctrl-arrows or home key when I don't want the cursor to go to the end of pasted text.
I actually found a way to do it with resharper - if any better suggestions out there please feel free to answer.
Create a simple template as
$END$$CopiedContent$
and set the CopiedContent variable to clipboard content. Give it a shortcut vc (ctrl-v inverted) - and have fun. It will require an extra left arrow and escape char to get desired effect.
It costs VC[TAB][Left_ARROW][ESCAPE] meaning 5 characters which is more than I originally wanted. Willing to trade for a better answer.

Get outside parentheses in Visual Studio 2013

All right, this is stupid, but I have no clue how people deal with this and I'm hoping I'm missing something...
When I write something like this:
if (n == 0)
...The closing parenthesis gets added as soon as I type the opening one. The only way I know of to get out of them now is to reach over and tap the End key or something, which kind of ... Damages my shui, you know? And yet apparently they thought this feature was a cool idea, so...
What do you normally do to tell the IDE that you're done with this bit and you're ready to move on to the next? Same question applies to automatic quotes and stuff in the XAML editor, I guess.
Just keep typing - if you type your own ) when the cursor is just before the automatic one, it should not create another ), but just move the cursor over it.
(Disclaimer: I'm not certain this works on a vanilla Visual Studio - I have a bunch of extensions installed)
You can press Ctrl + Shift + Enter to open a new line below the current one without moving the cursor to the end of the line.
To add to this, Tab is another option and I find it easier:
In your example, type the logic, press Tab to skip passed the end bracket.
If you are inside auto quotes, type your text, then press Tab twice.
Like the other answer, it only applies when first being typed, so if you go back to edit something, you are left using the End and Arrow keys.
In Visual Studio 2015 with Productivity Power Tools installed (probably works earlier as well), when being inside an auto-complete block (quotes or braces):
end goes to line end ( typically slow to type/find)
"/) typing same key as auto-complete already inserted will simply replace the auto-inserted character
tab jumps over end of auto-complete (e. g. braces or quotes)
shift+enter adds ; at end of line, goes to new line (often what you want)
ctrl+shift+enter goes to new line
There is a short key in VS - "Edit.LineEnd" - pressing "End" you get to the end of the current line. I've re-assigned it (for me the best variant was "Alt-Enter") and use it to get outside of parentheses and quotes.
Hit the enter key when you are done typing.

How to automatically keep the smart indent in visual studio

I don't quite know how to phrase this question, but basically what happens is:
if i smart indent in visual studio, then click somewhere else on the page or even on the exact same line that has the smart indent, it then goes away, as if I'd had no indenting at all, not even block indenting.
It just puts the cursor/insertion point at the very beginning of the line.
EDIT: BTW I recently formatted my computer and I'm almost certain this wasn't the case before, I'm guessing it's a setting, but I've been fiddling around with all the settings trying to change this, but I can't.
Open Tools->Options. Navigate to Text Editor on the LHS. Select the source type (C++, VB, etc.). Open the tree view node and select Tabs. There, on the RHS you'll find your option

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.

Use of Edit.SelectToLastGoBack in Visual Studio

There is a command in Visual Studio 2005 called Edit.SelectToLastGoBack (bound to Ctrl + =).
I presume it is supposed to select all the text between the current cursor position and the last 'Go Back' point, but I can't work out the algorithm it's using for deciding what that point is.
Does anyone know how to use this potentially very useful command?
Selects to the last juimp point ...
Try using the navigation bar to jump to another method in class. Then press Ctrl + "="
It will select from the start of method you jumped to all the way back to where you jumped from.
I have yet to find a use for it though TBH,
Kindness,
Dan
I use it for recording macros.
Frequently I want to select everything from this brace to that brace and cut it in a macro. Go to the first brace, hit ctrl-f (ctrl-i doesn't work right in macros), search to the second brace, close search with escape, and hit ctrl-= to get everything between the braces selected. This is much more reliably repeatable in a macro than something like using ctrl arrows to navigate a word at a time while holding down shift, and is similar to the emacs concept of setting a mark point.
I'm not sure what all starts a new 'location in navigation history', but I'm sure starting a search does and that's all I need.
I just discovered this command is available in Visual Studio 2012. I've been looking for it ever since I got VS 2012. I kept thinking it was something like anchor, like select everything between the anchor and point. I was disappointed that macro recording and playing are no longer available. But I am glad this command still exists.
Another useful command is ctrl+k ctrl+a, which is Edit.SwapAnchor. So, you could be someplace in the code, then do a find. Now you have the point and anchor (maybe also known as the cursor and last goback). You can do ctrl+= to select, then ctrl+k ctrl+a then extend from the other end using another find--or something like that.

Resources