101

My employer wants me to use IntelliJ for Java development. Previously, I've always used eclipse.

One of my favorite features in eclipse was being able to click on a variable, method parameter, class field, etc and see the usage of those variables highlighted throughout the class.

Is there a way to enable this feature in IntelliJ IDEA? I'm using Ultimate version 9.0.3.

Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
tau-neutrino
  • 3,270
  • 7
  • 25
  • 20

4 Answers4

168
  1. Go to File > Settings (Preferences on Mac)
  2. Go to Editor > Code Editing > Highlight on Caret Movement
  3. Enable Usages of element at caret.

Settings

KyleMit
  • 30,350
  • 66
  • 462
  • 664
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 11
    You'll definitely want to install the "Identifier Highlighter" plugin too, which allows you to easily navigate between highlighted usages. – Daniel Alexiuc Sep 20 '11 at 00:15
  • This option changes behaviour of enter key? After checking the option, hitting the enter key doesn't moves caret to a newline. Instead, it moves to next character. – mmdemirbas Mar 23 '12 at 11:54
  • 5
    Any way to change color of higlighted usages? – Xorty Mar 24 '12 at 10:41
  • 1
    Works by default in 12x it looks like – dbrin Sep 04 '13 at 18:10
  • This doesn't seem to highlight all instances of a variable. It only highlights access or usages, it won't highlight the variable if it's only being assigned, and it won't highlight the variable's declaration. Which in my use cases for highlighting, those 2 are like 99% of what I use it for: to figure out where the value in a variable came from. – Shufflepants Sep 16 '16 at 18:59
  • 2
    Using 2016.2 and this doesn't work at all. The setting was on by default, but it's not highlighting the variable my cursor is on (unless it is somehow the same colour as the non-highlight?) – Adam Nov 10 '16 at 09:04
  • 1
    IntelliJ IDEA 2021.3.3: File | Settings | Editor | General | Code Editing | Section "Highlight on Caret Movement" | checkbox "Usages of element at caret" – IndustryUser1942 Jul 15 '22 at 12:55
17

I think Intellij does not do this by default for a reason. If you click in a symbol on your code, you can hit Ctrl+Shift+F7, then it will highlight (High visible, not just like the default underline) all occurences of the symbol. Good thing is, if you move out the cursor of that symbol, it will keep it highlighted wherever you go.

Tip: You can highlight how many different symbols you want at the same time.
Tip 2: F3 / Shift + F3 goes to the next / previous occurence respectively.

Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101
12

Go into Settings->IDE Settings->Editor->Color and Fonts->General

Make a copy of Dracula to something like MyOwnDracula (can't change the built in schema).

Find whatever you need to change, in this case it's "Identifier under caret" and change the colors for foreground and background to your liking.

atom88
  • 1,449
  • 3
  • 22
  • 32
2

Even though this is a question on how to highlight all variables, point one and two will answer that meanwhile point 3 will make you more productive and rename all variables simultaneously if you so choose to do so.

  1. With your cursor on an occurence.
  2. Do Ctrl+Shift+F7 to select all other occurrences.
  3. Then Shift + F6 to rename all occurences simultaneously.
N Djel Okoye
  • 950
  • 12
  • 10