visual studio. Hot key for pasting some specific text - visual-studio-2010

I Find my self using jquery a lot in visual studio for my current project. Is there a way to add a hot key that will paste the guts of a selector on the screen? for example Ctr+shift+J will paste $("#").

Create a snippet:
Walkthrough: Creating a Code Snippet
What this will do is when you type a certain word (lets say selector in this case) and then hit the tab button, it will insert your snippet text that you defined.

Here's the macro solution:
Record a macro "Ctrl-shift-R"
Type specified Text (eg $("#").)
Stop Recording "Ctrl-shift-R"
Save your recorded macro: Tools-> macros -> save-temporaryMacro
Assign a shortcut key to your saved marco: Tools -> Options -> Enviornment -> Keyboard
Hope this helps someone. very nice!

Related

How to automatically format XAML code in Visual Studio?

Here:
https://social.msdn.microsoft.com/Forums/de-DE/b77c7529-298f-4b9a-874a-f94f699986ac/automatically-formatting-xaml-code?forum=vswpfdesigner
... it is written that one can use "Ctrl+K+D" ... but that didn't work.
I also tried "shift + alt + F", which was suggested here:
How do you format code in Visual Studio Code (VSCode)
... it didn't work either.
So my question is: how can you automatically format XAML code in Visual Studio?
Probably your formatting options are wrong, go to: Tools -> Options -> Text Editor -> XAML -> Formatting -> Spacing and on Attribute Spacing section click "Position each attribute on a separete line" and then try "Ctrl+K+D" again.
I would check out XAML Styler, which is a Visual Studio extension to help format your XAML source code (full disclosure, I am one of the owners on the project).
Edit: Forgot to mention that Visual Studio does not have a very rich set of XAML formatting capabilities on its own.
Shortcut key for XAML formatting in Visual Studio for Mac machines: Ctrl+I
In case you guys still don't know how...
It's called 'Format Document', you can find it inside menu:
Edit => Advanced => Format Document
There is also shortcut for it:
Ctrl+E then Ctrl+D
This works for most document, including XAML.
EDIT: When this post was made, I was using VS 2017
I use Xaml Formatter. Works pretty good for me. You will just have to assign code formatting with Xaml Formatter to a Ctrl+K Ctrl+D shortcut in Xaml files, since it is not done by default (it's creating Format Xaml option in Tools menu).
Also Inline Color Picker is a very simple but extremely useful extension if you are developing a lot of Xaml code.
Try using "XML Tools" for VS Code, the shortcut is Alt + Shift + F
For anyone who is searching for kind of combining "Insert a single space between attributes" and "Position each attribute on a seperate line" I found this solution:
Tools -> Options -> Text Editor -> XAML -> Formatting -> General -> Tag Wrapping
and tick "Wrap tags that exceed specified length".
Self-explanatory that one can adjust the length in the following input field.

Is there any way to export the contents of the watch window in VS2010

Is there any way to export the contents of the watch window in VS2010 similar to exporting break points. I need to be able to export the complete contents of the watch window(including all sub nodes) to a file.
I doubt it is possible to export contents of the watch window.
Alternative way - Export the datatips.
1. In a source window, place the mouse pointer over any variable in the current scope. A DataTip appears.
2. Right-click on a variable, then click Pin to source.
3. On the Debug menu, click Export/Import DataTips.
If you're just wanting to save the aOn the watch window, click on the root/parent object, right-click -> select all.
Then Copy and paste into blank excel workbook.
There is a visual studio extension available here.
Please take a look it as well.
If it does not help, then please follow below steps:
The goal is to write the variable values one by one to immediate window and copy from there to excel sheet.
#1. When the breakpoint hits, Menu ->Debug->Windows->Immediate(Or Ctrl+Alt+I in VS2019)
#2. Type the variable name, IntelliSense will list all of the properties of this root variable. Get the value of each and copy/paste to excel sheet.
Hope it will helps.
Thanks.

How do I record a Visual Studio macro to set Options settings?

I've just tried to record a macro to help me switch word-wrap in editors on and off quickly, but all the macro records is DTE.ExecuteCommand("Tools.Options"), which leaves me with a big, dumb open dialogue when I try and execute the macro.
How can I record or write macros to help me quickly set options, without the rudeness of the modal options dialogue? Are there any extensions I could use for this?
For a bonus point, is there a way I can automate Options changes without using macros, and without having to write a big VS extension?
switch word-wrap in editors on and off quickly
Maybe I'm confused, but word wrap is toggled by Ctrl-E, Ctrl-W.
is there a way I can automate Options changes without using macros
You can use the Visual Studio command window here:
View > Other Windows > Command Window
In addition to the Visual Studio Commands list, you can enter any Menu command in the command window. I found Edit.ToggleWordWrap, which toggles word wrap in the currently-focused text editor.
To bind a command (or several commands) to a shortcut key, create an Add-In (not a big VS extension ;). In your case, the relevant line would look like this:
cmd = cmds.Item("Edit.ToggleWordWrap", 1);
There's really no way to record a macro to set anything in the Options dialog. The macro recording infrastructure in general can't handle modal dialogs and essentially ignores them. The options dialog is no exception here.
The best hope here is to
Save the options out to a vssettings file
Hand code a macro which manipulates the low level IVs interfaces to set the options you want.
The vssettings file is the more viable, and far simpler, option

visual studio shell F# keyboard shortcuts

I've started using F# with the visual studio shell and I like the capability to be able to send lines to fsi by highlighting them, but the alt+Enter shortcut is really awkward and I would be much happier with this being on shift+Enter. (mainly since shift+ up/down arrow is select lines already)
Does anyone know how to change this? Thanks.
You can alter the keyboard mappings within Visual Studio. If you go to Tools -> Options -> Environment -> Keyboard, you'll see a window like the image below.
In order to check existing bindings, place the cursor in the "Press shortcut keys:" box and hit "Shft+Enter". You'll then see any potential conflicts in the drop-down box as shown.
In the example below, I'm searching through Global, which means shortcuts for anything in the application. You can switch it to be just the console or whatever you like.
Once you're happy with the shortcut you want to use, you need to select the command from the window containing all of the Action.* lines and then press Assign.
So I don't mean to be trite, but have you tried mapping the key?
So for F# Interactive I see Alt+Enter mapped to:
ClassViewContextMenus.ClassViewMultiselectProjectreferencesItems.Properties
Have your tried mapping Shift+Enter (or whatever) to that command?
Tools->Options->Environment->Keyboard
You should be able to get it all working from there.

How to assign keyboard shortcut to open a solution folder from visual studio?

I'm trying to assign a keyboard shortcut to open a solution folder (the one you get when right click on solution name) from Visual Studio. Looking in keyboard options in Options didn't help (searched for "folder", for "open" etc.)
Have I missed something ?
This is it:
ProjectandSolutionContextMenus.Project.OpenFolderInWindowsExplorer
It works, but I'm sure how you get the solution selected first?
Please let us know if you can solve it elegantly, I'm interested because I don't currently use AnhkSVN or VisualSVN, I prefer TortoiseSVN, but it would be nice to open the solution folder since that's normally the root.
You can assign a keyboard shortcut to a macro using this example
Assigning a Keyboard Shortcut to Macro in VS
Last time I forgot to mention one
important thing - how to assign a
keyboard shortcut to your macro. Often
you don’t need any button for your
macro, the shortcut is enough. Or you
can have both. As I already wrote,
macro is similar to any named command.
So to assign a shortcut to it:
Go to menu Tools - Options… and select Environment - Keyboard.
alt text http://www.helixoft.com/blog/wp-content/uploaded/keyboard_options.png
Find your macro in the list of commands. All macro names start with
“Macro.”. To filter out other commands
enter your macro name in the Show
commands containing field. If your
macro is named test as in our example
then type test. Select your macro.
Go to Press shortcut key(s) field and press your shortcut. If the
shortcut is already in use, you will
see it. Press Assign button.
Remember that you cannot change or
assign the shortcut if you are using
predefined keyboard mapping scheme.
You will be warned in this case. You
must create a copy of current scheme
and use that copy. Press Save As…
button under Keyboard mapping
scheme and give it some name. Then
select this new scheme.
There probably isn't a keyboard shortcut defined for that, but Visual Studio has excellent macro support, and you can create your own macro to do that.
There's a Macro Recorder feature that you can use. This MSDN article explains how to use the Macro Recorder.

Resources