简体   繁体   中英

How can I add “Toggle On/Off Code Lens” as a quick command button on Visual Studio?

I would like to have a quick command button displayed on my Menu bar to turn on/off the Code Lens. I understand there is a keyboard shortcut available for it:

The EditorContextMenus.CodeLens.CodeLensOptions command for keyboard shortcut, but I cannot make it as a quick command button.

It will be very awesome I can see a quick button on my VS Menu to quickly toggle it. (instead of remember it as keyboard shortcut)

How can I achieve this?

Apparently this is as hard as it looks - even though the command definitely exists, it is nowhere to be found in any of the menus when clicking "Add Command...". But this is a fixable oversight.

Here's what I did:

  • Made a copy %LOCALAPPDATA%\Microsoft\VisualStudio\<version>\Settings\CurrentSettings.vssettings
  • Added a random command to my menu bar
  • Removed "CodeLens Options..." from the respective menu using the command editor:
    在此处输入图像描述
  • Closed all instances of Visual Studio for changes to be flushed to disk
  • Ran an XML formatter on both files and then a diff on them
    (note: some diff tools like Beyond Compare have a built-in XML formatter)
  • The diff revealed the command's GUID and CmdPri:
     <remove Cmd="{7660636A-8C08-4430-A56F-146E42A8B2C5}:00000001" CmdPri="01000000" Group="{7660636A-8C08-4430-A56F-146E42A8B2C5}:00002000" GroupPri="01000000" Menu="{7660636A-8C08-4430-A56F-146E42A8B2C5}:00003000" IsPartialRemoval="false"/>
  • Modified my new command's Cmd and CmdPri to be that of the removed CodeLens command:
     <add Cmd="{7660636A-8C08-4430-A56F-146E42A8B2C5}:00000001" CmdPri="01000000" Group="{D309F791-903F-11D0-9EFC-00A0C911004F}:00000174" GroupPri="09000000" Menu="{D309F791-903F-11D0-9EFC-00A0C911004F}:00000001"/>

And voila - the command is now residing in the appropriate toolbar and you can move/modify it as you please:
在此处输入图像描述
You can now also go and reset the original CodeLens menu that you have removed it from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM