IntelliJ: 如何像 Eclipse 那样自动突出显示变量

我的老板希望我使用 IntelliJ 进行 Java 开发。

Eclipse 中我最喜欢的特性之一是能够单击变量、方法参数、类字段等,并查看在整个类中突出显示的这些变量的用法。

有没有办法在 IntelliJ IDEA 中启用这个特性? 我使用的是 Ultimate version 9.0.3。

26679 次浏览

File | Settings (Preferences on Mac) | Editor | General | Highlight usages of element at caret.

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.

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.

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.