Skip to content

IntelliJ IDEA

Created: 2020-02-26 14:52:26 -0800 Modified: 2022-03-11 10:22:10 -0800

  • File colors: the setting for “File Colors” (Settings → Appearance & Behavior → File Colors) is actually really nice. By default, it highlights non-project files yellow and test files green. This affects the Project view and your open tabs, but it also affects stack frames in a stack trace. So, for example, when you’re debugging, it’s common to see a large blob of yellow frames representing that those frames are the boilerplate that your runtime is providing (e.g. Java + Swing frames will typically show at the bottom for UI events).
  • Disabling specific warnings: if you want to disable a specific warning, you can press alt+enter to bring up this dialog:

  • Then press the right arrow to go to the next menu:

  • Choose “Edit inspection profile setting”, and from there, you can disable the warning (alternatively, you can choose “Disable inspection” to prevent having to go to another menu).
  • Double-shift (i.e. pressing shift twice) is how to access the command palette which can get you to practically anything. You can also open files this way.
    • This is also how you can get access to JavaDocs, e.g. shift+shift → “nametag” to find an API with “nametag” in it
  • Alt+enter is the magic-fix-it shortcut.
  • F2 will move to the nearest issue
  • Ctrl+Q is the quick help for getting tips on the current type, the return value of a function, etc.
    • Ctrl+P is the same thing for while you’re typing out parameters
  • Alt+insert is how you can generate methods, e.g. a constructor. The location where you press the hotkey is where the code will be added.
  • Ctrl+shift+A is where you can write some actions and save them for later use
  • Ctrl+alt+F will convert the selected variable into a field (AKA a class member). Pressing enter again after that will remove its declaration from the current function. You don’t even need a selection when you do this; IntellIJ will ask what scope you want to extract.
    • Ctrl+alt+V is the same thing but for a local variable
    • Ctrl+alt+M is for method extraction
  • If you write out an expression, e.g. “event.getBlock()”, you can type “.var” afterward to have it automatically extract the variable type into a declaration on the current line.
    • If you just type ”.” after anything and scroll down, you can see all of the completion options, e.g. “nn” for “not null”. You can also make your own.
  • “fori” will get you a classic “for” loop with numerical iteration.
    • Likewise, if you have an iterable collection that you want a “foreach” for, you can do “values().for”.
  • To get JavaDocs and source code automatically in a Maven project, there’s a “Download Sources and/or Documentation” button (you can find the Maven panel via double-shift → Maven).
  • When you add a dependency to pom.xml, you may want it to autoimport that dependency (like installing Node modules with a package.json). The setting for this is in Settings → Build, Execution, Deployment → Build Tools → Maven → Importing → Import Maven projects automatically.
  • To run Maven goals, click this button: