Is it possible to create custom hotkey binding commands in visual studio? - visual-studio-2010

For example, I'd like to bind Ctr+H to the keyboard Home key or Ctr+l Ctr+b to the keyboard [ key. I've found the Tools -> Options -> Environment -> Keyboard options but the commands, while very extensive, are still limited. I'm hoping this is extensible.

There is no out of the box way to handle custom key bindings. You need to write your own VS Extension. However, there is some really great documentation out there on how to do this.
http://msdn.microsoft.com/en-US/library/dd885474.aspx - A MSDN Walkthrough specific to key bindings.
http://blogs.msdn.com/b/jasonz/archive/2009/06/01/visual-studio-2010-sdk-beta-1-is-now-live.aspx - A general tutorial on VS Extensions
http://www.microsoft.com/en-us/download/details.aspx?id=2680 - The VS2010 sdk.

Related

Visual Studio Auto Tidy?

I have a question about how to enable automatic code tidying property in Visual Studio. I have no idea whether I have used the word correctly or not. What I'm doing is that I'm using Visual Studio in my personal laptop and also on a separate computer. In the laptop when I'm working on writing C++ code when I press "Enter" all the code automatically rearranges so that it looks more elegant and tidy. I did not enable it on purpose; I just like it and I would like to do the same thing on another computer as well. Is there anyone out there who knows how to do this stuff? Thanks.
I believe you're referring to "code formatting" support. Each language (C#, C++, VB, etc.) have their own implementation of this. To trigger it directly, you can find the command in the menus by going to Edit -> Advanced -> Format Document (or Format Selection). There are also keyboard shortcuts that do it, I use CTRL-E, D all the time, but that may be language specific so you should experiment some.
Hope that helps.
You can either Format Selection by using CTRL+K, CTRL+F and you can format the whole document by pressing CTRL+E, D.
You can also do this by going to Edit -> Advanced -> Format Document/Format Selection
For more options about formatting you can go to Tools -> Options -> Text Editor -> C++ -> Formatting

Custom tool shortcut visual studio

Is there a way to create a shortcut for a custom tool in visual studio? At the moment I have to navigate to the tool in the solution, right click and run custom tool. It would be nice if I could either bind a shortcut key or run the tool from the toolbar. Does anyone know of a way to do this?
I think you are looking for this:
Go to Tools -> External tools
Configure your tool
Go to Tools -> Options -> Environment -> Keyboard
In Show commands containing type: Tools.ExternalCommand
Choose the command you want and set a shortcut for it.
In the External tools, the gotcha is that the number of the external tool is the position in the list.
Yes, go to Tools -> Options -> Environment -> Keyboard..
Look for command Project.RunCustomTool or the command you actually want.

Is it possible to implement a "Vim" toggle in Visual Studio?

Ie, specify [ctrl][alt]+v or something...and that would instance vim inside that text editor window... because that would be really cool.
And/Or: is there a way to do it yourself, if you wanted to? Ie, can you attach custom functions to the keyboard keys and whatnot? I noticed that a lot of the Add-Ins seem to be able to kindof accomplish that level of customizability...
There are a few projects that incorporate vim keybindings directly into the Visual Studio editor.
Here's one: VsVim
I'm using VsVim
You download the plugin from the link above, double click on it and it will be installed in all VisualStudios you have installed in your computer.
About toggling VIM in VisualStudio:
I don't think you can enable/disable it per tab or file openned: either is enabled or disabled in all files.
What you could do is this: add a new shortcut to enable or disable it when you need it.
Tools -> Options... -> Environment -> Keyboard
On the "Show commands containing" input type "VsVim.ToggleEnabled". For me this command wasn't bind it with anything. I added the shortcut
Ctrl Q, Ctrl V

How do I set AppUserModelID on shortcut?

I'm in Windows 7 working on combining two apps with the same task bar icon, as described in this question:
Pinning advertised shortcuts on the taskbar in windows 7
I see there, and it lots of online documentation that I need to set the AppUserModelID as a property of the shortcut. My installer program uses the basic Visual Studio 2008 setup project, and I don't see any way to set shortcut properties on installation. Is there any head-start anyone can give me on how to do this?
Sheng commented that "You can also switch to other MSI authoring tools that supports setting the appid for shortcuts, such as WIX or NSIS."
To achieve this using a Shortcut element in Wix you must add a child ShortcutProperty element to your Shortcut element and use the Shell property name "System.AppUserModel.ID" as the key.
<Shortcut Id="StartMenuShortcut"
Name="Shortcut Name"
Description="Shortcut Description"
Target="[INSTALLLOCATION]Application.exe"
WorkingDirectory="INSTALLLOCATION">
<ShortcutProperty Key="System.AppUserModel.ID" Value="AppUserModelID" />
</Shortcut>
I don't know anything about VS2k8 setup projects so I don't know if you can run custom actions etc but I do know that to set the AppId on a shortcut you load/create your shortcut and query its IShellLink for IPropertyStore, then InitPropVariantFromString a variant with your id and call SetValue(PKEY_AppUserModel_ID,propvariant) + Commit on the propertystore
Adding to Ander's reply.
Visual Studio Setup project does not support setting appid and will probably never be unless Microsoft reverse the deprecation of Setup project feature.
There is a Windows API Code Pack that helps in invoking shell APIs. Here is a tutorial on creating shortcut in custom action. You can add the code to update the shortcut to the custom action.
You can also switch to other MSI authoring tools that supports setting the appid for shortcuts, such as WIX or NSIS.

Resharper and ViEmu Keybindings ( and Visual Assist )

With ViEmu you really need to unbind a lot of resharpers keybindings to make it work well.
Does anyone have what they think is a good set of keybindings that work well for resharper when using ViEmu?
What I'm doing at the moment using the Visual Studio bindings from Resharper. Toasting all the conflicting ones with ViEmu, and then just driving the rest through the menu modifiers ( Alt-R keyboard shortcut for the menu item ). I also do the same with Visual Assist shortcuts ( for C++ )
if anyones got any tips and tricks for ViEmu / Resharper or Visual Assist working together well I'd most apprciate it!
You can also create mappings in ViEmu that will call the VS and R# actions. For example, I have these lines in my _viemurc file for commenting and uncommenting a selection:
map <C-S-c> gS:vsc Edit.CommentSelection<CR>
map <C-A-c> gS:vsc Edit.UncommentSelection<CR>
The :vsc is for "visual studio command," and then you enter the exact text of the command, as it appears in the commands list when you go to Tool>Options>Keyboard
I don't use any of the R# ones in this way, but it does work, as with:
map <C-S-A-f> gS:vsc ReSharper.FindUsages<CR>
I use both as well, but I'm using the IntelliJ keybindings instead, so I can't speak specifically to the Visual Studio bindings. J.P. Boodhoo has some changes that he has made via AutoHotKey to provide additional Vim-like functionality to Visual Studio + ReSharper + ViEmu.
I have removed a few of the scanned keys, though, because I want to keep some of the ReSharper functionality over the ViEmu functionality, though the way I use these tools change over time as I learn more shortcuts from either ViEmu or ReSharper.
I have noticed the following, which may be useful to know. Some of the ReSharper keyboard mappings that ViEmu hoses, will work once you have a different ReSharper dialog open. I use the IntelliJ IDEA-based shortcuts, but I assume this will work similarly for ReSharper's VS scheme.
Example: ViEmu binds to Ctrl+N which R# uses for Go To Type. However, ViEmu does not bind to Ctrl+Shift+N which R# uses for Go To File. Therefore, if you hit Ctrl+Shift+N the Go To dialog is launched. You can then take your finger off Shift and hit N again and the dialog will switch to Go To Type.
This is very useful, if like me you use Go To Type a lot and don't really want to mess with the keyboard mappings.
As #Jay noted the best way is to set up custom bindings.
Here is example of bindings at https://github.com/StanislawSwierc/Profile. I created my bindings based on the previous at https://github.com/w1ld/viemu_settings
I use both plugins, but I really prefer the power of the Vi input model that ViEmu gives. I really don't miss so much the Resharper keybindings...

Resources