Navigating code
Tips to help you navigate through your codebase.
Navigating code is a crucial skill that we can get faster at with our IDE by using the various keyboard shortcuts to move around the codebase based on recent context, what something in the code does, or to move backwards and forwards based on our movements in time. We will look at:
- Viewing Recent Files and Locations
- Going to a Declaration or Implementations
- Navigating Forward and Backwards & Preview Tab
Viewing Recent Files and Locations
You can think of ⌘E (macOS) / Ctrl+E (Windows/Linux) as your working context. Many users rely on Editor Tabs for this, but you can turn them off and use Recent Files to navigate around the files that you've opened recently.
In addition to Recent Files, IntelliJ IDEA allows you to go to your Recent Locations ⌘⇧E (macOS) / Ctrl+Shift+E (Windows/Linux) which is most helpful when you are navigating around specific points in longer classes.
Going to a Declaration or Implementations
Go To Declaration or Usages ⌘B (macOS) / Ctrl+B (Windows/Linux) is a great way to answer the question "Where is this declared?" or "Where is this used?".
Similarly, Go to Implementation ⌥⌘B (macOS) / Ctrl+Alt+B (Windows/Linux) can tell you and subsequently take you to where a method has been implemented.
Navigating Forward and Backwards & Preview Tab
Sometimes you just want to flick between a few files in the same order that you opened and navigated through them. You can do that with ⌘[ (macOS) / Ctrl+Alt+Left Arrow (Windows/Linux) to go backwards and ⌘] / (macOS) Ctrl+Alt+Right Arrow (Windows/Linux) to go forwards.