26

I would like to have a quick keyboard shortcut to turn on/off this feature. The feature is useful, but sometimes I want to look only at code and this feature distorts the code visual appearance.

I have bound EditorContextMenus.CodeLens.CodeLensOptions to a keyboard shortcut, but this is too slow because the Options menu takes too long to open. I would really like to have shortcut that toggles this feature on and off.

How can I do this? Did I miss some option in Environment->Keyboard or is there some add-on that can help?

g t
  • 7,287
  • 7
  • 50
  • 85
watbywbarif
  • 6,487
  • 8
  • 50
  • 64
  • 2
    You can vote for this to be added: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/4246480-add-shortcut-to-quickly-open-close-codelens-func – DixonD Nov 06 '15 at 11:36

2 Answers2

21

To automate the Options dialog, you can create the following command in Visual Commander and assign a keyboard shortcut to it:

DTE.ExecuteCommand("EditorContextMenus.CodeLens.CodeLensOptions")
System.Windows.Forms.SendKeys.Send("{TAB} {ENTER}")
Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
  • 4
    Had to add System.Threading.Thread.Sleep(300) before sending keys so that keyboard modifiers don't mess up the command. This is one theory, second is that CodeLensOptions needs time to initialize and start accepting keys? – watbywbarif Aug 03 '15 at 07:02
  • Nice! When typing "Editor" into the Command Window, the very first option in the auto fill drop down just conveniently happens to be the one for CodeLens . So it's actually *almost* just as easy to do the shortcuts manually if you don't care to get the VC extension. – BVernon Feb 07 '19 at 20:59
  • 1
    I ended up using this method and it worked well. Here is a walkthrough for installing it and setting up the shortcut keys (blog's author credits this answer): https://lassala.net/2017/07/18/toggling-visual-studio-codelens-onoff/ – CSquared Jan 26 '21 at 23:41
8

Interesting. Codelens already has some keybindings associated with it. If you press down ALT, it shows numbers over the indicators (references, source control, test), but as far as I know there isn't one to turn on/off the indicators. I'll take this feedback and file a bug for the team that owns the codelens UI at Microsoft.

balajikris
  • 201
  • 2
  • 7
  • 1
    just wanted to provide an update that this bug was accepted and is being considered for a future version of VS. Meanwhile, I discovered that right clicking on the indicator brings up a flyout that opens up the tools -> options page for codelens. – balajikris Feb 15 '16 at 20:35