I'm working on creating a training course for IntelliJ IDEA (I've been working on it for a while now, I don't really want to talk to much about it because I'm not sure when I'll actually deliver it). Anyway, as I was thinking through Features You Really Need To Know, I realised that it's not really about code completion and code generation, it's about those features that will get you out of a big, deep hole that you've dug yourself into.
So, I put together my top five features that have saved my bacon, and recorded a video for the Continuous Delivery channel. I have asked around and these features should work for all JetBrains IDEs, not just IntelliJ IDEA.
As usual, I have included the transcript below so you can skim it and skip to the bits that interest you.
Transcript
We all make mistakes. You could argue that computers help us make mistakes much faster and more regularly. I want to show you some features from IntelliJ IDEA which have helped me personally recover from some of these mistakes. More importantly, they've stopped me wanting to destroy my computer in frustration.
Hello and welcome to the Continuous Delivery channel. I'm Trisha Gee. The very first keyboard shortcut that I taught my eldest child when I was showing her how to use the computer is Ctrl+Z. I did not teach her Ctrl+C or Ctrl+V until after I had taught her Ctrl+Z. In the various pieces of software she was using, she would sometimes need to get back to a known good state, and knowing the shortcut for undo helped her a lot.
I hope most people watching this video already know about Ctrl+Z. If you don't, please start using it as soon as possible! In this video, I'm going to show you some more advanced features of IntelliJ IDEA, which can act as a sort of advanced undo, or allow us to get to some known good state after things have gone terribly, terribly wrong.
I have five tips I want to cover:
- Local history, for getting lost changes or lost files back.
- Using the debugger to go back in time.
- Clipboard history, which is personally one of my favourite features of IntelliJ IDEA and I wish all software had it.
- Reverting our settings when we've made changes which are not working for us.
- And finally, I'm going to show you an all round, helpful, "fix this for me please" shortcut.
1. Local History
There was one feature in particular I wanted to show you which inspired this whole video. Then I asked social media, "which are the features that you use the most to save you from uncomfortable situations with IntelliJ IDEA?". This feature, Local History, was by far the most quoted feature.
I know that you're all using version control, you do small commits, you make small numbers of changes, that you are in control of the situation as you make changes to the code. And I know that local history is not something you're necessarily going to rely on because you're using a more structured version control system for that. However, I know there are times when standard version control is not enough. Either you've accidentally made a whole bunch of changes, which you might not realize you got carried away with, or you accidentally switched branches or did something else where you trashed your entire local changes. This is what local history is for.
Trisha Tip: the video here shows a live demo of me using the feature
To get to local history, I usually use Find Action (⇧⌘A | Ctrl+Shift+A) because that's my favorite keyboard shortcut for finding something if I don't know the keyboard shortcut. You can also use Search Everywhere (⇧⇧ | Shift+Shift), and then you can type local history. You want to select "show local history" for this. This will show you the local history for the file that you were just changing. It shows small incremental changes. All of these changes have been made since the last version control commit. So these aren't version control commits.
IntelliJ IDEA was making a note of all the individual changes that I was making as I went along. It even includes things like refactoring. So I can revert to any one of these, I might want to go right back to the beginning, but probably I'll use version control for that. I might click on a specific change and revert to before this point.
Another very helpful feature of local history is the ability to add labels to it. So if my code is in a place where I want to make a comment about it, like "this code does not work", I can go to file -> local history -> put label, and I can type "does not work". Then it will add like a bookmark at this point in the history. So I know that this is not the code that I want. Or I could have typed "it works right now". We can use these labels to tag the history as we go through it.
Where local history has been really helpful for me in the past is being able to retrieve files that I've deleted that I did not mean to delete. I usually do that by looking at local history on the project window.
You can right click on a folder in the project window and select "local history". You can see this file was deleted. I can see where it is and what the path is. If I revert that change, I've got that file back.
2. Reset Frame
Let's talk about the debugger. IntelliJ IDEA's debugger is ridiculously powerful, and even people who use it regularly don't use 5% of the features. I'm not going to go into the details of all these esoteric debugger features. I'm just going to show you one thing which you did not know existed, which is going to save your bacon when you're debugging an application.
Trisha Tip: the video here shows a live demo of me using the feature
So let's run the debugger. And usually when you're debugging something, you'll hit the breakpoint a few times. You'll just skip over that as you do. Maybe what you might do is step over, and then as you're stepping over it, you're like, "Oh no, I really, I wanted to step into that line!". What you often end up doing is just restarting the whole debugging context.
But you don't need to. Look for this tiny little icon here, called Reset Frame. The method I'm in was called by this method. If you reset the frame, it takes you back in time to this method call from before you skipped over the breakpoint. So you can run it back to the start of the breakpoint, and then you can step into your line like you wanted to.
That's my top tip for helping with the debugger. You can look for this little tiny reset frame icon.
3. Clipboard History
My next tip is less about recovering from mistakes, and more about the ability to reuse things that you thought were lost.
This is about clipboard history. IntelliJ IDEA records a history of all the things you've ever copied or cut in the past, not just the last thing that's on the clipboard. So you can use (⇧⌘V | Ctrl+Shift+V), and it shows you everything that you've copied in this session of IntelliJ IDEA. It doesn't take stuff from outside: from the operating system or from other applications.
It does show you everything that you've used inside IntelliJ IDEA. So if a few copies ago, you happened to copy the version of Gradle and you need that now, you can just scroll down to that or press the number next to it to paste that specific thing from your clipboard history.
4. Reset Settings
Now I want to talk about when you change some settings and the IDE is not behaving the way that you expect it to. Let me show you a few tips for undoing some changes.
Trisha Tip: the video here shows a live demo of me using the feature
Firstly, when you open up your settings window, you'll find the things that you've changed. For example this is in the inspections settings. The settings that are different to the defaults are in blue. Any changes that I do make, if I decide that I don't want to keep them, obviously I can press cancel, or I can click on the revert link at the top of the screen. This reverts the changes that are specifically on this page of the settings. Perhaps I might want to keep some of the changes I've made on one screen of the settings but reset others on a different screen.
Something else that's useful is using the arrow buttons at the top to go backwards and forwards through the changes that we've made.
One more thing around settings. Let's say that we can't just go back and revert one thing or cancel the changes we just made. We might want to reset all of the changes across the board. We've clearly done something very wrong. Then we're going to go to file -> manage IDE settings -> restore default settings. Although first you might want to backup and sync, but after that you want to restore default settings.
I quite often do this anyway, especially because over time the defaults in IntelliJ IDEA change and sometimes I want to try out whatever the most recent set of defaults are in case they're more sensible. If you have a highly customized IntelliJ IDEA, you might not want to do this!
5. Fix this!
Finally, I want to show you a keyboard shortcut I hope that you all know if you're using IntelliJ IDEA. But what I'm going to show you is perhaps even more places to use it. So the keyboard shortcut is (⌥⏎ | Alt+Enter), which I expect you probably use a lot already.
For example, if you see grey like this, you press (⌥⏎ | Alt+Enter) and it tells you, you can delete that, nothing's using it. If you see a warning Then you can use (⌥⏎ | Alt+Enter) to get it to fix the code for you. It's a really helpful shortcut just to try and get IntelliJ Idea to reshape the code the way that you want it, or at least maybe try and fix some errors or warnings that you're seeing.
What's probably most interesting, I think, for (⌥⏎ | Alt+Enter) is that you can use it even when there isn't an error. So in this example, we have completely fine working code. We have no grey things here. We have no yellow warnings. We have no squiggly underlines, but we can still press (⌥⏎ | Alt+Enter) here and get options on how to change the code.
(⌥⏎ | Alt+Enter) is my magic fix all keyboard shortcut for if I'm looking at some code, I'm not really sure what's wrong, it might be an error or it might just look weird, then I might want to use (⌥⏎ | Alt+Enter) just to say, what can I do with this code here?
I find that when I've dug myself into a deep and nasty hole, IntelliJ IDEA can help me climb out of it. It's not just these five features that I've shown you today. When I asked social media for people's favorite features for getting them out of trouble, I got loads of different suggestions.
So play with these features that I've shown you, but also have a quick look around YouTube or social media for other examples of helpful features.
If you want more tips on how to successfully use IntelliJ IDEA, buy my book!