My Favorite Shortcuts for JetBrains' IDEs
Apr 11, 2020 09:30 · 1215 words · 6 minute read
JetBrains, the makers of the popular IntelliJ IDEA, offer a range of powerful IDEs for all kinds of programming languages. At work, we use them as well - I am using PhpStorm and GoLand a lot.
IDEs are full of features - shortcuts enable you to access these features much faster. They make you a much faster programmer, so you can concentrate on solving actual problems and not loose time fiddling through menus. 😉 They are an essential part in improving one’s software development craft.
I would like to share the shortcuts that I am using the most. All shortcuts here are given for a Windows keyboard layout:
- When clicking on a method call: Jump to the method’s implementation
- When clicking on a method signature: See usages of the method.
- Alternatives: Keyboard-only Ctrl+B, mouse-only Middleclick.
- Ctrl+Shift+A: Search in Actions. This is an awesome starter shortcut: You can use it to learn which other actions exist. Each action in the result list is accompanied by its shortcut - so you can use this feature to improve your action & shortcut knowledge! Besides that, I use it for executing actions I don’t use often (like increasing or decreasing the font size).
- Ctrl+Shift+N: Search in File Names (and Paths). Also useful: Adding a
:<LINE-NUMBER>suffix - this will let you jump directly to the respective line. Especially nice when you already know the line of an error (e.g. because of a compiler error message).
- Ctrl+G: scroll to a specific line (a popup will open, where you enter the line number)
- Ctrl+F12: See & access the structure of the current file - e.g. method names or class attributes. Useful: When the popup is open, you can directly start typing - the list will be filtered!
- Finding text
- Ctrl+Shift+F: Search in contents of all files. Tip: When you have selected a folder in the left project tree view and then use this shortcut, only this folder is searched (not the whole project).
- Ctrl+F (obvious, but included for completeness): Search inside the current file.
- Similarly, these shortcuts let you “Find and Replace”: Ctrl+Shift+R and Ctrl+R.
- Shift (two times): Search everywhere. This is the master search, a combination of all specialized searches - it will search in actions, file names, symbols (like method names),… I used to use it more often, but nowadays I prefer the faster more specialized searches.
Refactoring & Code Generation
- Alt+Enter: See IDE suggestions (e.g. when your cursor is on a line with an error or a warning)
- Shift+F6: Rename a symbol (e.g. a method name or a variable name).
- Ctrl+Shift+Alt+T: See possible refactorings (e.g. extract some code into a separate method, extract some value into a constant…)
- Alt+Insert: To generate stuff (e.g. a constructor, getters/setters)
- Ctrl+W: Extend selection (e.g. for selecting the whole word, the whole method…)
- Likewise, Ctrl+Shift+W lets you un-expand the selection.
- Ctrl+Tab: Open the “Switcher”, e.g. to switch between open files.
Git Version History
I set up the custom shortcut Ctrl+Shift+G to toggle annotations ( G for Git). So I can easily see when each line of code was last modified and access the commit. This helps me understand the context for a modification.
This was all for now, I hope this blogpost helped you with improving your efficiency with JetBrains’ IDEs!
After sharing this blog post in our internal company channel, a nice discussion emerged and my colleagues shared some of their favorite shortcuts as well! Here are they:
- Middleclick: A mouse-only alternative to Ctrl+Click and Ctrl+B. I now mention it there. (Thanks Cagatay!)
- Alt+J: When doing a text search, this shortcut adds the next occurrence to the selection. You can then edit all selections at the same time (multi-cursor). (Thanks Philipp!)
- The shortcut for doing the opposite is Alt+Shift+J (unsurprisingly).
- Shift+F6: Rename a symbol (e.g. a method name or a variable name). I use this shortcut every single day - how could I forget about it? I now added it to the list of refactoring shortcuts.
- F2: Jump to the next problem/IDE suggestion. I did not know about this, but I think this is super-useful. This could very well become one of my most-used shortcuts. (Thanks Jens!)
- Ctrl+E: Show the list of recent files. This could possibly become my replacement for Ctrl+Tab, as this is what I want most of the time - and is easier on my fingers. (Thanks Benjamin!)
- Ctrl+Shift+E: Similar to
Ctrl+E, but shows all recent positions incl. the surrounding lines. 🤯 A potentially very powerful feature! (Thanks Torsten!)
- The “Show shanged only” toggle is especially useful.
- Good to know (already familiar from other modals): When the overview is open, you can just start typing and it will filter instantly by file name & code.
- Alt+Shift+ArrowLeft/Right: Navigate to the last/next edited location. I think this could be very useful as well! (Thanks Sebastian F.!)
- Similar & potentially even more useful: Ctrl+Alt+ArrowLeft/Right: Navigate to the last/next selected location. (Thanks Stefan!)
- Ctrl+/: Comment/Uncomment line (or selection). This can be very useful and I will try to remember it for when I need it! (Thanks Sebastian A.!)
- Note: On your NumPad, “/” might be printed as “÷”.
- Ctrl+Y: Delete line (Thanks Sebastian A.!)
- Ctrl+D: Duplicate line (Thanks Sebastian A.!)
- Alt+Shift+ArrowUp/Down: Move line up or down (Thanks Sebastian A.!)
- Very similar is Ctrl+Shift+ArrowUp/Down which lets you move whole methods as well.
- Ctrl+P: Show the list of parameters for a function call. (Thanks Jens!)
- An interesting tip by Cagatay was to modify your IDE’s shortcuts so that they match the shortcuts you already know from your browser. So you do not have to remember two different shortcuts for the same thing. Examples include Ctrl+T for opening a new tab, Ctrl+Shift+T for reopening a closed tab, and Ctrl+W for closing a tab.
- F11: Toggle a bookmark on the current line. I don’t use the bookmarks feature, but can see how this can be useful. (Thanks Jens!)
- Ctrl+Shift+Alt+Insert: This creates a new “scratch” file, a temporary file e.g. for notes. I use other tools for such temporary files (I did not know about this feature before), but can see how they can be useful, especially when you do not want to leave the IDE for that, and/or want to profit from your IDE’s features like syntax highlighting (Thanks Cagatay!)
My brother (Thanks Andy!) reminded me of the very useful shortcut Ctrl+Alt+L to reformat selected code. For my work projects, I mostly trigger this action via “Find in Actions” (I should really remember this shortcut though…). For my own personal projects, I can luckily spare it and use automatic code formatters like Prettier to re-format my code on every save.
This post was discussed on HackerNews - a very interesting discussion with over 60 comments!
I recently learned about shortcuts to navigate between previous/next cursor locations (& added it to the “Navigating” section)!
- Customizing my shell: From bash to zsh to fish
- JSON5: JSON with comments (and more!)
- jq: Analyzing JSON data on the command line
- Get Total Directory Size via Command Line
- Changing DNS server for Huawei LTE router
- Notes on Job & Career Development
- Adding full-text search to a static site (= no backend needed)
- Generating a random string on Linux & macOS
- Caddy web server: Why use it? How to use it?
- Tailwind CSS: A Primer