There are two related questions about resetting VisualStudio keyboard scheme and importing VisualStudio settings. However, this doesn't seem to play nice all together.
I have two settings files containing shortcuts:
<!-- IntelliJ.vssettings -->
<ShortcutsScheme>Visual C# 2005</ShortcutsScheme>
<UserShortcuts>
<Shortcut Command="ReSharper.ReSharper_GotoNextHighlight" Scope="Global">F12</Shortcut>
</UserShortcuts>
<!-- ReSharper.vssettings -->
<ShortcutsScheme>Visual C# 2005</ShortcutsScheme>
<UserShortcuts>
<!-- Implicitly has F12 assigned to Edit.GoToDefinition -->
</UserShortcuts>
As you see ReSharper.vssettings
doesn't really have the F12
shortcut assigned, since it is the default for VisualStudio. Importing that file, will not reapply the ShortcutsScheme
, which is Visual Studio C# 2005
in both cases. This in turn results in the fact, that F12
keeps executing the GotoNextHighlight
command. Same problem when just using the import dialog.
Using DTE
as follows to reset the keyboard scheme also doesn't work:
var property = dte.Properties["Environment", "Keyboard"];
property.Item("SchemeName").Value = "(Default)";
Exporting the default settings doesn't work for the same reason. As shown here no shortcuts are exported.
Question therefore: How can I reset the VisualStudio keyboard scheme programmatically using DTE?
What I actually need is the command to trigger the Reset
button in Options | Environment | Keyboard dialog.
You can remove specific key bindings as per: Visual Studio key bindings configuration file
Unfortunately I dont have both IntelliJ and ReSharper to test if it works. If it does it'd be nice to do this using DTE however this solution is beyond the scope of DTE and would be trivial using System.IO.File.
UPDATE:
Unfortunately you cannot do it (AFAIK) because resetting the Keyboard Shortcuts is beyond the scope of DTE.
If you setup a VS AddIn Project called "ResetKeyBoard" and put a break point on the
Exec
method you will see DTE doesnt catch any Visual Studio events firing when you're inside the Tools Options window, they simply aren't exposed through the DTE Object model:This can also be demonstrated by Recording a Macro, the recorded commands only go so deep as to open the Option Dialog (no matter what settings you change inside):
I did learn how to open the Keyboard tab of the Options window directly but since its a Modal Dialog you cant even use SendKeys to press the Reset button:
The last DTE option I tried (without luck) is using
Commands.Raise
, again you cant get deeper than opening Tools Options or at least if you can its undocumented.Workarounds:
a) I dont encourage you to replace the Visual C# 2005.vsk file, but if you want to investigate its this file:
MSDN Warning
I do not recommend or encourage this method, its bad programming and you could destroy someone's keyboard shortcuts!
b) Another way could be by creating your own VSK file and setting it in the currentSettings.vssettings:
Make sure you backup the currentSettings.vssettings file before changing it.
c) This leads back to Chris Dunaway's suggestion where you create a vssettings file (purely containing keyboard shortcuts) and import that in to reset the keyboard shortcuts. I realise the default shortcuts are not saved, however here is some code you can use with DTE to export the commands out, to insert into a new vssettings file to then import in:
Once you've got them out its easy to import them in:
REFs:
Visual Studio 2005 IDE Tips and Tricks
How to reset visual studio settings to my saved settings with just a single shortcut?
How does one set Visual Studio 2010 keyboard shortcuts comfortably, especially when using ReSharper?
https://superuser.com/questions/914244/is-there-a-quick-way-to-delete-all-shortcuts-in-visual-studio-10
Remove a keyboard shortcut binding in Visual Studio using Macros
http://vswindowmanager.codeplex.com/
Get full list of available commands for DTE.ExecuteCommand
HOWTO: Execute a command by Guid and Id from a Visual Studio package
HOWTO: Execute a command by Guid and Id from a Visual Studio add-in
HOWTO: Pass parameters programmatically to a command from a Visual Studio add-in
And finally this one by Jared Par:
https://github.com/jaredpar/VsVim/blob/master/Src/VsVimShared/Extensions.cs
You can call devenv.exe directly and pass the /ResetSettings switch. Here is a link to the command line options for Visual Studio: https://msdn.microsoft.com/en-us/library/xee0c8y7.aspx
You can execute devenv.exe using the Systems.Diagnostics.Process class to reset the settings:
You can, optionally, pass a settings file which contains the settings you want to restore:
In Visual Studio, you can export selected settings by going to Tools > Import and Export Settings... and selecting "Export Selected Environment Settings". Then, only choose the Keyboard checkbox under the All Settings > Options > Environment subtree.