Remove a keyboard shortcut binding in Visual Studio using Macros

三世轮回 提交于 2019-12-06 05:35:21

问题


I have a lot of custom keyboard shortcuts set up. To avoid having to set them up every time I install a new visual studio (happens quite a lot currectly, with VS2010 being in beta/RC) I have created a macro, that sets up all my custom commands, like this:

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

My main problem is that Ctrl+T is set up to map to the transpose char command by default. So I want to remove that default value in my macro.

I have tried the following two lines, but both throw an exception

DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing

Although they kind of work, because they actually remove the binding ;) But I would prefer the solution that doesn't throw an exception.

How is that done?


回答1:


I have coped with the same issue. I use a macro to assign key bindings for a set of align macros.

Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...

And to remove key bindings i use the following statements :

Dim DelBindings() = {} 
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings

It works fine under Visual Studio 2005.




回答2:


I followed a little more pragmatic way (using your example):

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

With the first assignment Ctrl+T is unassigned from any other function and then becomes unbound with the second assignment.

Works like a charm for me.




回答3:


You do not need to change it with macro, Just go to

Menu>Tools>Options -- Keyboard and then select what you want to change the shortcut from the dropdown and assignyour desiered short cut



来源:https://stackoverflow.com/questions/2324550/remove-a-keyboard-shortcut-binding-in-visual-studio-using-macros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!