4

I've been using monodevelop for a while and was using the 'Monokai' theme. Its coloring was very detailed. As you can see in the screenshot the local and global variables have different colors. Monodevelop colors

Recently I've started using Visual Studio 2017 and can't seem to find a theme that uses different colors for local and global vars.

Visual Studio colors

I've tried going to Tools->Options->Environment->Fonts and colors and couldn't find any setting to individually adjust the text colors of locals and globals. Even though I name these differently, the coloring makes debugging and code reading a bit more easier.

Does anyone know a way to give unique colors to local and global variables?

3 Answers 3

4

This is the default behavior now. VS 2019 and 2022 now color global and local vars/parameters differently by default.

Customized under Tools > Options > Environment > Fonts and Colors.

For C# these are the items starting with User Members -.

2
  • Yeah not for C#. I had to install SemanticColorizer like Aj_ mentioned.
    – jsirr13
    Jul 26, 2021 at 22:12
  • 1
    @jsirr13 I just edited the answer to show which fields apply to C#. Thanks to stackoverflow.com/a/57007495/825588
    – Johann
    Oct 26, 2022 at 19:09
3

Okay, I installed an extension called SemanticColorizer and that did the trick. Still, if anyone has any other solutions, please post it here.

1
2

I do not believe there is a way to do this within Visual Studio. There may be a 3rd party add-on/extension that may do this.

UPDATE:
Visual Studio 2019, via a software update, recently changed the granularity in which variables can be color 'coded'. Please see Alex's response below for the now correct answer.

5
  • You maybe right. But I still hope someone can come up with a solution.
    – Aj_
    Mar 29, 2018 at 18:50
  • 1
    That's why most people will use an underscore as a prefix for a global variable.
    – EL MOJO
    Mar 29, 2018 at 18:58
  • Yeah, I do that too. But having different colors makes it a bit more easier to quickly identify them.
    – Aj_
    Mar 29, 2018 at 19:52
  • See Alex's answer, it is possible now in VS2019 Nov 1, 2020 at 21:29
  • 1
    Thank you @tscissors. I've updated my 'answer' to tell future readers that Alex's answer is now the correct answer.
    – EL MOJO
    Nov 5, 2020 at 16:19

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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