Visual Studio 2013 custom toolbar to insert code snippets - visual-studio-2013

Could anyone point me in the right direction here? I am adding a custom toolbar and I want buttons for lots of different code snippets. We use so many that it is impracticable to remember all the different shortcut commands for each one, and selecting from a menu takes longer than just clicking a button.
It doesn't really even need to be specifically for a code snippet as defined by Visual studio, just simply pasting some text to the editor window, however I was hoping to be able to have some that would work as surround snippets, which the normal code snippets do.

You should call this:
(DTE2)base.GetService(typeof(DTE))
in the Initialize() method of the Package and save the resulting dte-instance in a field. When your button is clicked, you can use ((TextDocument)_DTE.ActiveDocument).Selection.Text) to retrieve the currently selected text, modify it and write it back as new selected text. Maybe you will have to cast the return value of the Selection-Property to TextSelection.

Related

Change variable name in multiple lines in visual studio

So, I have some code for a Rect variable mageSection:
And I'd like to copy the same code for a different variable warriorSection. To achieve this:
So I'd like to know if there is a visual studio shortcut for allow you to change variable name in multiple line in visual studio without refactoring the whole variable name.i.e. I don't have to manually change those names from mageSection to warriorSectionfor these 4 lines.
It is a question about shortcut in visual studio rather than writing functions, as I'd like to know the shortcut for this. Many thanks!
Copy and paste the section of code.
Now select the pasted code and hit Ctrl-H to bring up the Quick Replace dialog.
In the top box, type "mageSection".
In the bottom box, type "warriorSection".
Hit Enter and it will find the first occurrence and replace it.
Hit Enter three more times...done.
If I'm understanding your question correctly you should be able to hold down alt while clicking into multiple lines and change them all at once. Then hit ESC to exit multiline editing.

Visual Studio: How to insert tab instead of code snippet

Whenever I hit the key after a keyword that comes from the list of code snippets, Visual Studio always inserts the code snippet.
However, this is very disturbing when I want to add one-line comments to existing code. I can't, for example, add a TAB character after the else keyword.
What keyboard combination do I have to press in order to get a TAB character inserted here?
Your help is appreciated.
A simple workaround for your else scenario is to insert a space and then the tab character, then remove the space.
If you want to make changes to snippets, you can do this by going to Tools -> Code Snippets Manager (Ctrl-K, Ctrl-B) and select the snippet you wish to modify. The path to the .snippet file will be shown. You can just open the file in a text editor and modify it to do the action you want.

Can I add my own code snippets to xcode 4?

It'd be really handy to have collection KVC accessor snippets in xcode, as they're a pain to do by hand. Has anyone who's been using 4 for a while worked out how to add new ones?
(...we're allowed to talk about it now, right?)
Yes, it's quite easy - you just highlight text you want to use as a snippet and drag it into the snippets area (dragging selected text can be difficult, I find it works better if you drag from the left edge of the editor). It brings up a dialog box asking you to name it.
Also, you can have custom parameters in snippets - if you put the text <#paramName#> anywhere in the code you are dragging, when you use the snippet it will come up as a replaceable parameter that you can tab between just like in the official Snippets.
Also make sure to set a completion prefix, which makes it shorter to activate the snippet as you are typing. The nice thing about using Snippets over other solutions like global system text expanders, is that snippets can also be limited to being valid in a certain area of code - so for example a snippet that filled out a string formatting line can be marked as valid only within a block, not outside a method. That way the completion prefix only hits in areas where it's valid to use.
You can edit a snippet by clicking once on it, a box will come up with the snippet text and some other snippet settings you can edit.
A tip to help you drag the code every time, select text then click + hold (do not move mouse) until mouse pointer changes from "I" to pointer. You'll then be able to drag the selected text to the Code Snippet Library.
Drag the highlighted code to the Snippet library. (It can be stubborn and not want to drag. Holding the mouse button down for a moment before dragging seems to help.)
You can use Snippets to manage code snippets in Xcode. Check out this demo http://www.youtube.com/watch?v=il4kE4diy0k
Simply select the code, the press ALT key and drag it into the code snippets library and rename it there, Make sure to press the ALT key, other than this you won'n be able to drag it.

Show Current Function on Toolbar in Visual Studio 2010

I wish to show the current function my cursor is in. I sorely miss this feature from VS6, I have tried customizing the toolbars but it should be no surprise I can't find it within the maze of hundreds of toolbar items, does anyone know what it is called and where its located? Or if its possible?
Let me give you an example. I'm debugging and see a variable is set to a certain value, I need to examine where this is set, so I search for variable name, Ctrl-F, F3, F3, F3, when the cursor is moved to the next result and if its in the middle of function I need to know very quickly what function its in, scrolling or any mouse interaction is a major slowdown in this process, I use the keyboard 90% of the time during my dev.
PS: note to visual studio developers. When you toolbar item list contains over 5,000 items it might be time to make it searchable lol!
In Visual Studio 2010, the code editor window has a toolbar at the top called the "Navigation Bar". In C++, C#, and VB the right-hand drop down in the Navigation bar is dynamically updated to reflect the current function or method that the cursor is in. You can read more about the navigation bar here:
How to: Navigate Code and Text

How do I change the auto complete behavior in the VS 2010 editor?

How do I stop VS 2010 (RC) from autocompleting html helpers with new object { ... } when I just want to pass in an anonymous type? Backspacing is driving me crazy.
e.g., VS wants:
<%=Html.ActionLink("Register", "Register", new object { controller = "Account" }) %>
I know the helper is declared expecting object, which is why it does this, but can I change this behavior just for mvc helpers?
Theres a button on the Text Editor toolbar that "Toggles between suggestion and standard completion modes" (the default shortcut for the C# developer keyboard layout is Ctrl+Alt+Space). It will prevent the editor from filling in the selected item if you just type "new {" (it's actually meant to allow use-first development).
Note: You will need to hit the up or down arrow to give focus to the suggestion if you actually want Intellisense to fill it in, otherwise typing one of the word-break characters will just dismiss the prompt without modifying what you have typed.
Yes, it is annoying. I just press Escape after the space after new. This cancels the Intellisense window that will fill in object.

Resources