205

I've searched but didn't find any info on how to disable references (or the codelens completely) in the Visual Studio Code, they're quite useless and annoying for me.

6
  • 1
    @Louy Google is your friend, but a short description might be that it adds annotations inline with your code, to show you certain details that you might not otherwise see, such as counts of references to properties and fields.
    – Elkvis
    Sep 14, 2016 at 18:01
  • 2
    I created an extension called Setting Toggle which lets me turn the codeLens on and off easily. My extension also lets you toggle any vs code setting. I found the jumping code when loading C# files very annoying, however the reference count is really helpful sometimes.
    – user6322327
    Jun 15, 2018 at 17:07
  • 3
    2019 and still codelens is annoying. It would be nice if it was only shown at focus but until then, it looks much better without it.
    – Spiral Out
    Oct 21, 2019 at 18:08
  • 4
    2021 and still codelens is annoying.
    – outdead
    Jun 13, 2021 at 16:08
  • 4
    @Elkvis It's 2022 and not only is codelens still annyoing but this page is the top result on Google for "visual studio code disable codelens"
    – MiffTheFox
    Mar 7, 2022 at 3:21

9 Answers 9

210

You can enable or disable code lense by setting editor.codeLens to true or false in user settings (see https://code.visualstudio.com/Docs/editor/editingevolved#_reference-information for more info).

4
  • 13
    Latest vscode has a search function in the settings, just type in codelens and uncheck the box.
    – Edwin
    Nov 15, 2018 at 8:34
  • Where is settings?
    – Sam
    Apr 22, 2022 at 12:11
  • I just right clicked on one of the references in a class and they all went away.
    – Sam
    Apr 22, 2022 at 12:13
  • @Sam Are you saying that you couldn't find menu item File - Preferences - Settings? Oct 6, 2022 at 10:36
158

Update: in the new settings editor of VSCode, it's as simple as typing codelens in the search and ticking the first checkbox in the results:

enter image description here


For me, the setting that fixed it was:

"editor.codeLens": false

in my user preferences json file.

1
  • 4
    Ctrl + , (comma) to quickly open Settings and start searching. For reference for anyone like me who doesn't have it memorized. :) Oct 7, 2021 at 19:18
33

Step by step:

1- Press CTRL+SHIFT+P and search for "User Settings", and open settings.json file. This file sits under:

%UserProfile%\AppData\Roaming\Code\User\settings.json

CTRL+SHIFT+P

2- On right panel override setting "editor.codeLens" with "false" value.

editor.codeLens

0
33

To specifically disable the references in the C# editor, add this to your User Settings:

"csharp.referencesCodeLens.enabled": false

This specifically hides the number of references in the C# editor while keeping the rest of CodeLens' features intact.

MotKohn also pointed out that you can use javascript.referencesCodeLens.enabled or typescript.referencesCodeLens.enabled below. Make sure you give them some points if that helped!

0
19

I disabled it by going to file | preferences | settings

file preferences settings

Finally:

Workspace | Text Editor | (scroll down a little)

enter image description here

10

For people using any Linux OS:

  1. Go to File > Preferences > Settings
  2. Under drop-down Text Editor, search for Code Lens and disable it.
5

You can do it using a single click on VS Code. Just install the extension Setting Toggle made by Ho-Wan on VS Code. Once you install, click on T as shown in the image to toggle Codelens.

enter image description here

2
  • Looks a bit awkward, but works very well! Upvoting! By default it is setup to toggle Code Lens, so no configuration needed. Bonus: you can now toggle lens from Chift+Ctrl+P by typing Setting toggle. Apr 16, 2021 at 13:25
  • This is a great piece of additional information! It doesn't exactly qualify as an answer to the question where it is only asked to permanently disable Code Lens. But for those who want to disable/enable Code Lens on the fly, this is great! Thanks for sharing :)
    – ADTC
    Nov 26, 2021 at 9:48
1

Shortcut to toggle this feature on/off quickly: CTRL+SHIFT+P Toggle TypeLens

2
  • Please indicate why you are downvoting this answer. It is a valid answer to the question asked. I offered it up as an alternative to workspace/user settings for those interested. Jul 31, 2019 at 19:45
  • This doesn't appear to be a VS Code native feature. Perhaps you are disabling it for the TypeLens extension. You need to mention that in the answer.
    – ADTC
    Nov 26, 2021 at 9:46
1

The editor.codeLens property doesn't seem to work for F#, at least for the inline type-annotation lens. I needed to set:

"FSharp.inlayHints.typeAnnotations": false

to disable it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.