2016-12-15 33 views
0

你好VS 2015是越野車,我不時恢復我的一些捷徑。 F.E. ctrl +;爲LineEnd和其他人。有沒有辦法通過宏等來實現這個程序?如何編程爲VS操作創建visual studio鍵盤快捷鍵?

已解決。有更新腳本,不清除分配給VS命令所有鍵盤快捷鍵(它有助於避免develor VSIX):

using System; 
using EnvDTE; 
using EnvDTE80; 

public class C : VisualCommanderExt.ICommand 
{ 
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    { 
     string commandName = "Edit.LineEnd"; 
     string shortcut = "Text Editor::ctrl+;"; 

     EnvDTE.Command cmd= DTE.Commands.Item(commandName, 0); 

     // Retrieve the current bindings for the command. 
     Object[] bindings = ((System.Object[])(cmd.Bindings)); 
      // Get the number of bindings for the command. 
      int bindingNumber = bindings.Length; 
      // Add two more elements to the array to accomodate two 
      // new commands. 
      // Create temp variable for copying values. 
      // Arrays are zero-based in C#. 
      object[] temp = new object[bindingNumber + 1]; 
      System.Array.Copy(bindings, temp, Math.Min(bindings.Length, temp.Length)); 
     bindings = temp; 

      // Add the new bindings to the existing ones in the array. 
      bindings[bindingNumber] = shortcut; 

     cmd.Bindings = bindings; 
    } 
} 
+0

如果你的安裝有問題,你應該修復它,而不是假設VS是越野車,並試圖掩蓋它。問題將繼續存在,可能會變得更糟。至於快捷鍵,爲什麼不簡單*重置*他們?或從「工具>導入和導出設置」導出/導入它們? BTW LineEnd只是結束鍵。 –

+0

檢查[識別和自定義Visual Studio中的鍵盤快捷鍵](https://msdn.microsoft.com/zh-cn/library/5zwses53.aspx)。它顯示瞭如何導出設置,包括鍵盤快捷鍵 –

+0

您可以運行devenv.exe/ResetSettings以恢復整個IDE的默認設置。如果你不介意丟失任何其他可能的定製,那就是。 –

回答

1

您可以使用下面的命令我Visual Commander擴展:

public class C : VisualCommanderExt.ICommand 
{ 
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    { 
     this.DTE = DTE; 
     SetShortcut("Edit.LineEnd", "Text Editor::ctrl+;"); 
    } 

    private void SetShortcut(string commandName, string shortcut) 
    { 
     EnvDTE.Command command = DTE.Commands.Item(commandName, 0); 
     command.Bindings = shortcut; 
    } 

    EnvDTE80.DTE2 DTE; 
} 

Command.Bindings文檔更多細節。

+0

謝謝。偉大的工具,它解決了我的問題,也許有一個硬核:)警告這scritp從vs命令中刪除所有定義的鍵盤快捷鍵。 – Igor