General Tips & Tricks
Become an IDE power-user with these bite-sized tips and tricks.
Development is about focus and flow. Learning your tool helps you get into the flow and stay there.
This playlist shows a variety of IDE tips and tricks from across the major usages of GoLand.
Find Actions in Any JetBrains IDE
Find various actions inside your JetBrains IDE quickly and efficiently.
The Problem
You want to move a line up. You could use the mouse to select the line, cut it, go to the next line up, and paste it. You know the IDE has an action that can do it, but…what is it?
Let’s use the mouse and look in the Edit menu. Hmm, not there. How about Code? Ahh, yes, it’s there, with the keyboard shortcut. Maybe you speed that up by learning the shortcuts. There’s the Keyboard Shortcuts PDF. You could try memorizing all of that... possibly but nor probable.
The IDE has a lot of power, which means a lot of actions, with new ones coming in each release, not to mention plugins. You’re not going to memorize all them. Does the IDE have a better way?
The Solution
What you need is Find Action, a single keyboard shortcut to memorize. The one ring to rule them all. ⌘⇧A (macOS) / Ctrl+Shift+A (Windows/Linux):
Type “move line up” and you’ll see the Move Line Up Action. Bonus: the keyboard shortcut is shown when an action has one.
That’s a lot to type. Instead, use speed typing to type just fragments such as "m | u". Maybe you don’t know the full action name. Just type one word to get in the ballpark such as "type".
One last point: Find Action also matches preferences, and some are inline toggleable. Want to disable tabs without opening settings/preferences? Start Find Action and type ta pl no for the Window | Editor Tabs | Tabs Placement: None preference. Press Enter to toggle it.
Remember…you don’t have to remember! Keyboard shortcuts, that is. Let Find Action be your one-stop-shopping for actions.
Reduce Clutter by Disabling Tools
Save space by turning off various toolbars.
Use View | Appearance: Tool Window Bars to toggle all the IDE tool windows visibility.
This helps you maximize your work space in the IDE.
Disable Tabs
Save space and stay keyboard-centric by turning off the tabs.
Want a cleaner UI with less noise to juggle in your head?
There are better choices for moving between files than tabs. Let's turn them off.
Tabs are a great way to focus on the few files for a task. However, they have some downsides. Try disabling your tabs as a first step towards a more-focused, keyboard-centric workflow.
Control the tab placement to position where the tabs are in the IDE. Invoke Tab placement | None to hide them completely.
Use Recent Files
Jump to any of the files you've been using recently in your JetBrains IDE.
The Problem
Have you ever been deep into a project, only to realize that you forgot to include something crucial in a file? We've all been there, so let's learn how to prevent this from happening to us again. While the tabs at the top of your screen are helpful, they can be a little bit overwhelming.
The Solution
Instead of searching for a certain tab, let’s use our IDE. One convenient way to find certain files is using the Recent File Window. It gives you a nice list of all the files you have visited recently. It is automatically sorted in the order you have visited them, which makes going back so much easier
Well, that is already a great improvement, but we can do even better! What if the file you are looking for is at the very bottom. Well sure we could press arrow down like a hundred times, or worse use the mouse, or we just type directly into the window, which lets you search for a particular file.
Wouldn’t it be nice if you could narrow it to only the files you edited, not all you visited? In the upper right corner, you see the “Show edited only” files. This will help you remove some clutter and hides the files you just visited without doing any changes, and you can even open a certain file in a split window to have a look at multiple files at the same by clicking on the icon on the right side or pressing Shift or Enter.
I got one more for you, let’s check it out! If we look to the left side of our Recent Files Window we see all the amazing tools we recently used. You want to jump to the Terminal? Just type in “T-E-R” and it will take you right there.
Development is hard! and having a good overview of edited files is difficult. Luckily our IDEs make navigation really convenient!!
Navigate to Symbol
Navigate your project by code, not files.
Use Navigate to Symbol to jump between symbols in your project and stop thinking about the file they are in.
Invoke it using ⌘⌥O (macOS) / Ctrl+Alt+Shift+N (Windows/Linux) to bring up the search window and quickly navigate your way in the project.
Navigate to File
Jump to a file without using the Project Tool Window, and your mouse
The Navigate to file feature allows us to search for a file by name, even if we know only part of it.
You to search for a file in the current project only, your source code only, or all places. This means you can search in other places like Go Modules dependencies and GOROOT.
How to use:
Press ⌘⇧O (macOS) / Ctrl+Shift+N (Windows/Linux) to invoke Navigate to file.
Pro tip:
As a hidden gem, try finding a directory by name.
Navigate Cursor Position Back and Forth
Navigate back to where you were, or where you went quickly and easily.
Use the Navigate | Backward and Navigate | Forward to go up and down the code path you are exploring while navigating from one symbol to another.
To go Backward, ⌘[ (macOS) / Ctrl+Alt+Left Arrow (Windows/Linux).
To go Forward, ⌘] / (macOS) Ctrl+Alt+Right Arrow (Windows/Linux).
Activate the Navigation Bar
Turn the navigation bar on when you need it and dismiss it when you're done.
The Problem
Getting into the flow means stripping down your UI distraction (turn off the Project tool window and Navigation Bar) then going keyboard-centric to avoid the mouse. But you still need to get to your files, and sometimes you'd prefer to browse instead of invoking "Recent Files" ⌘E (macOS) / Ctrl+E (Windows/Linux) or "Find File" ⌘⇧O (macOS) / Ctrl+Shift+N (Windows/Linux) action.
The Solution
In the latest version of JetBrains IDE's, the Navigation Bar is in the Status bar by default, but you don't want to use your mouse to get there, or perhaps you've already hidden it altogether as part of a lean UI.
You can invoke Navigate | Jump to Navigation Bar ⌘↑ (macOS) / Alt+Home (Windows/Linux) to temporarily re-activate the Navigation Bar. Once you use it, the window disappears.
But then, how do you make it disappear? Press ␛ (macOS) / Escape (Windows/Linux) to go back to where you were working.
How did we hide it in the Navigation Bar first place, or bring it back if wanted? From the menu, you can select View > Appearance > Navigation Bar which allows you to toggle between Top, In Status Bar and Don't Show.
Want a faster, keyboard-centric way to toggle? ⌘⇧A (macOS) / Ctrl+Shift+A (Windows/Linux) lets you search for such settings and even toggle inline. Type vi nav
to speed search, make sure the selection is on View: Show Navigation Bar, then press ⏎ (macOS) / Enter (Windows/Linux). The setting is toggled...no mouse usage needed.
Create a new File from the Navigation Bar
A fast way to add a new file to your project, without touching the mouse.
The Problem
How can I create a file if I've turned off the Project tool window? Let the Navigation Bar be your one-stop replacement for the Project Tool window!
The Solution
In your JetBrains IDE, invoke the "Navigation Bar" with ⌘↑ (macOS) / Alt+Home (Windows/Linux)
You can now:
- Use the cursor keys to get to the target directory
- Speed search to select any subdirectories
Once you have selected your target, use ⌘N (macOS) / Alt+Insert (Windows/Linux) to bring up the new file dialog. Just like in the Project tool window, the new file is opened after creation.
Also like the Project tool window, your selection doesn't have to be on a directory. If you're on a file, the new file will be created as a sibling. This is particularly useful in the common case of creating a new file in the current directory:
- Activating the navigation bar highlights the current file.
- Immediately press New ⌘N (macOS) / Alt+Insert (Windows/Linux)
In summary, after two key combos, you have a new sibling file, with no permanent file tree visible and no popups to close afterward. That's what getting in the flow is about.
Find in Path with the Navigation Bar
Use the Navigation bar and Find in File together and be faster than all of your team members.
The Problem
Do you need a fast way to find files in a path, without disrupting your flow? Perhaps you've closed the Project tool window and need to find a file somewhere in the project tree?
The Solution
You can invoke Navigate | Jump to Navigation Bar ⌘↑ (macOS) / Alt+Home (Windows/Linux) to temporarily re-activate the Navigation Bar. Once you use it, the window disappears.
Navigate to the target, and invoke "Find in Path", ⌘⇧F (macOS) / Ctrl+Shift+F (Windows/Linux), from the keyboard.
Add Line After/Before
Smart-add a line either from the middle of a line, after or before the current line.
Language-aware line adding, no muss no fuss.
Press ⇧⏎ (macOS) / Shift+Enter (Windows/Linux), and you can add a line and place the cursor on it.
Press ⌘⌥⏎ (macOS) / Ctrl+Alt+Enter (Windows/Linux) to add a line above.
Expanding/Shrinking Selection
Use your keyboard to quickly select the portions of code that you need.
Use Extend Selection to quickly select parts of your code using semantic knowledge about it.
Selected too much, or using an already existing selection, and want to reduce the selection scope? Use the complimentary Shrink Selection feature.
Press ⌥↑ (macOS) / Ctrl+W (Windows/Linux), to Extend Selection.
Press ⌥↓ (macOS) / Ctrl+Shift+W (Windows/Linux) to Shrink Selection.
Move Block Up/Down Using Keyboard
Use the keyboard to move a line or selection up or down in your file.
Move lines and blocks, up or down, using the keyboard.
When you're in the flow, you want to re-arrange code fast. Use this tip to move code around without cut-and-paste.
Move Statement Up with ⌘⇧↑ (macOS) / Ctrl+Shift+Up Arrow (Windows/Linux).
Move Statement Down with ⌘⇧↑ (macOS) / Ctrl+Shift+Up Arrow (Windows/Linux).
Reformat Your Code
Reformat a specific piece of code or the whole file according to your preferences.
The Problem
You're busy hammering out line after line of amazing code but when you're done, and you look up to marvel at your masterpiece, you see that the indentation is all wrong.
The Solution
You can quickly reformat the whole file by invoking "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).
As you'd expect, this works in any JetBrains IDE.
However, what if you just want to reformat just one block of code? For example, maybe the whole team changed their code style, and you don't want a large full file reformat to be part of this specific commit. In that case, select the code you want to reformat and again invoke "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).
You can reformat code at the directory level too! Invoke your Project tool window ⌘1 (macOS) / Alt+1 (Windows/Linux), select the directory you want to reformat and invoke "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux) again. A word of warning here, you probably don't want to mix large commits that include reformatting and code changes - it can make deciphering the commit harder for the next person.
Lastly, there are additional settings you can use for reformatting your code which you can access by invoking the "Reformat Code Dialog" ⌘⌥⇧L (macOS) / Ctrl+Alt+Shift+L (Windows/Linux). The options here will vary depending on which type of code you're working with so try it out and see what you can learn!
Want to learn more?
Generate Imports While Typing
Avoid interruption by letting GoLand generate your imports as you type.
Tired of stopping your coding to go write an import?
Type what you want, let GoLand do the rest.
You could scroll up, type your import, find where you were, and resume. Instead, just type your symbol and let Go make the import. No distractions.
Install and Import
While typing a symbol, let GoLand install it and generate the import.
Type the symbol, let your IDE install the package and write the import.
GoLand can generate your import for you, even when you haven't installed the package.
Press to invoke the list of quick-fixes on the red import line and select Sync packages of <project> to import the package into your project.
Adding Fields to a Struct
Let your IDE add constructor arguments to your instance.
Use a Quick Fix to generate the missing field of a structure.
Put your cursor on a field that's missing, press ⌃⏎ (macOS) / Ctrl+Enter (Windows/Linux), and let the IDE generate the corresponding field in the structure definition.
Rename a File and its References
Change your mind on a file name, and the IDE makes all the changes for you.
Rename files with peace of mind.
Changed your name about what you named a file, and now you need to rename the test and example files too? Let the IDE handle all this work.
Invoke Rename Refactoring via ⇧F6 (macOS) / Shift+F6 (Windows/Linux), and do the work, safely and quickly.
Rename Symbol
Change a variable name, class name, or other symbol, across the project.
Refactor names quickly, across all projects at once.
Put your cursor on a symbol and refactor it. All usages in the project change with it.
Invoke the Rename Refactoring via ^T (macOS) / Ctrl+Alt+Shift+T (Windows/Linux).
Quick Documentation
View arguments and documentation without interrupting your flow.
Want to learn what a symbol is about, without going to a browser?
The IDE knows the symbol, its argument names/types/defaults, the documentation it has. Let it give you a non-interrupting window, letting you get back to work.
Invoke the Quick Documentation feature using F1 (macOS) / Ctrl+Q (Windows/Linux), learn more about the different symbols you're working with.
View Parameter Info
Quickly see function arguments and argument types.
Have a function with lots of arguments? Or a struct with many fields? Parameter Info gives just the basics without using lots of real estate.
Press ⌘P (macOS) / Ctrl+P (Windows/Linux) to invoke this feature.
With your cursor in the parentheses, invoke Parameter Info. You get a tiny popup with the positional and keyword arguments, along with any default values. Bold is used to mark the current spot in the parameter list that your cursor is at.
You can invoke this before you type any parameters, after you've typed a few, or later if you come back to make a change.
Working with Conditional Breakpoints
Learn how to stop your JetBrains IDE debugger when a certain condition is true.
The Problem
You have a bug in your code, but it's only happening when you've run through a certain number of iterations, or a certain condition is true. You don't want to sit there and click Step Over twenty thousand times, so what can you do?
The Solution
You can use the Condition property on the breakpoint to enter a boolean value and tell the debugger to stop when that condition becomes true.
Place your caret on the line you want to investigate and then invoke "Toggle Breakpoint" ⌘F8 (macOS) / Ctrl+F8 (Windows/Linux). Right-click on the breakpoint and enter a value that evaluates to a boolean and click Done:
Invoke "Debug" with ⌃D (macOS) / Shift+F9 (Windows/Linux) and note that the debugger now stops when the condition is true:
This works in any JetBrains IDE. You can also hover your mouse over the line numbers in the gutter, right-click and select Add Conditional Breakpoint, once again entering a boolean expression in the Condition property and clicking Done:
Once again, the debugger will stop when your condition evaluates to true:
Side note here, if you prefer the debug icon to be adjacent to your line number rather than on top of it, you can right-click in the gutter and select Appearance and then clear Breakpoints Over Line Numbers to configure it.
Evaluate Expression During Debugging
Select your code and execute it, in the right context.
Get the right answer in the right context, no typing.
Stopped at a breakpoint and want to see a result, either typed in or from a line fragment?
Invoke Evaluate Expression via ⌥F8 (macOS) / Alt+F8 (Windows/Linux).
Split Screen Without Tabs
Get your code and tests side-by-side without using tabs.
You can view multiple files at the same time using Split Horizontal and Split Vertical.
Invoke the Split Horizontal or Split Vertical via Find Action, ⌘⇧A (macOS) / Ctrl+Shift+A (Windows/Linux), then type the action names you need.
Run Single Test
Speed up testing by focusing on one test.
Want to focus your testing on just one test? Then you can launch the test under the cursor using a shortcut.
To launch the test under the cursor, invoke the test runner via ⌃⇧R (macOS) / Ctrl+Shift+F10 (Windows/Linux)
Auto-Run Tests
Get into testing mode by telling GoLand to automatically re-run tests as you type.
Test-driven development (TDD) means always run your tests.
GoLand makes that easy by automatically running tests after a small period of wait time.
You can also configure the wait time to suit your style.
Spot Coverage Gaps Using the Gutter
Let the IDE help you spot coverage gaps in your testing.
GoLand offers a builtin feature to allow you to run the tests in your project and display the coverage in a tool window as a summary for a package (folder) and file, and for each file, next to each line in the file.
Launch the test with Coverage support and then use the Coverage tool window to navigate to your packages/files and see their coverage.
Clone from GitHub
Create a project in your JetBrains IDE by cloning it from GitHub
The Problem
You want to work on a project that's hosted in GitHub, but how do you get it from there on to your machine?
The Solution
The first step is to get the link from GitHub. Navigate to https://github.com/ and navigate to the project that you want to use to create your project locally. You normally want to clone the main branch which will be selected by default. Click the green Code button and leave it on the default of Local. Click the icon to the right of the HTTPS link to copy the link to your clipboard:
Now you have three choices for pasting it into your IDE.
- If this is your first time opening your JetBrains IDE, you'll see this welcome screen. The Get from VCS option is the button on the right:
- If you have already opened some projects, perhaps locally, you'll see this screen instead. The Get from VCS option is a button on the top right.
- Alternatively, if you are already in a project, you can access the Project from Version Control option either from the File menu or from the File > New menu depending on the IDE.
Paste the link that you copied from GitHub into the dialog box that opens when you choose one of these options:
And then click Clone. The clone action copies the entire repository to your local machine including all the files, branches and commits.
And that's it, you can now work on the project locally, perhaps your first step is to make a branch!
Put New Project Under Version Control
The fastest way to register a new project directory under local version control.
Work safely via VCS, via the keyboard.
You started a new project or opened a local directory, and it's not yet under VCS. Here's the fastest way to do so, from the keyboard.
Edit Commit Message
Edit the wording in your last commit message, after you committed.
That last commit message…(sigh)...had a typo. You haven’t pushed yet. Just right-click on the commit, choose “Edit Commit Message”, and fix the mistake.
Now your commit history…passes the spell-checker.
The Problem
This is my development life. I finally wrap up a big pile of work, go to do a commit. And, in the rush of victory, make a spelling error, which I spot just as I finish clicking “Commit”. Alas, it’s there, in the history.
We haven’t pushed. So there’s hope.
The Solution
Of course, the best solution is to fix the problem before committing. Our IDEs have a plugin called Grazie which does...let’s just call it “super cool spelling and grammar checking.” It probably warned you about the typo.
It will probably even fix the typo for you.
Back to our messed-up commit message. We could of course, go to the Terminal and type some arcane commit message. And of course, hope we don’t corrupt our repo. This has some downsides: go to the command-line, type something a little obscure, possibly get something wrong, and get no help from the spell checker.
Fortunately, this is the kind of thing our IDEs are great at. Right-click on the commit, and you’ll get a list of actions to take on that commit.
There are LOTS of things we can do to help, as this list shows.
Beside Edit Commit Message, you can see F2 (macOS) / F2 (Windows/Linux).
This shows we could have skipped the context menu by selecting the commit and pressing F2 (macOS) / F2 (Windows/Linux).
We’ll select that option and be prompted with a dialog to edit the commit. The existing commit message is there. We can see, there’s a warning about the typo. We can hover the mouse for more detail. This is the Grazie plugin helping us again.
We can type to fix it, or use ⌥⇧⏎ (macOS) / Shift+Alt+Enter (Windows/Linux) to get a correction.
Once fixed, click Ok to finish the operation. You now see the commit history with the fixed commit message.
One point in closing...we mentioned that you should only use this option if you haven’t pushed. If you go back to older commits and right-click, you’ll see some options are grayed out.
Undo your Last Commit
Undo your last Git commit
First go to the Git tool window and make sure you’re on the log tab.
It shows the list of commits on the current branch. The most recent one is at the top.
Right-click that commit and in the pop-up window, choose Undo Commit.
That commit has some changes. Let’s keep them in the default changelist. Now the commit tool window says I have changes.
And now that commit…never happened. Let’s look a little deeper.
The Problem
You are editing, say a Markdown file. Let’s leave the Commit tool window and Git tool window open, to see the updates as we go.
You change the title, and make a commit. And for the thousandth consecutive time, you spot a typo, just as the onkeyup event fires when clicking commit. Alas, the commit tool window shows that there are no changes. And, in your Git log, there it is, the mistaken commit.
That means it’s too late, right! Nope, if you haven’t pushed to a “protected” branch, you can clean things up locally. And the IDE puts a convenient UI atop the underlying Git command.
The Solution
In the Git tool window, find the most recent commit. It’s the one at the top. When we select it, we get more detail about the commit. We can double-click the file to see a diff of the change.
When you right-click on a commit, you get some actions you can take on it. Some might be grayed-out. For example, if we right-click on an older, pushed commit, we’ll see “Undo Commit” is grayed-out.
Back to the first commit. Right-click on it, and select “Undo Commit”.
Now, the commit had some changes in them, and these changes need to go somewhere.
The IDE’s changelists provide such a place.
We’ll stick with the Default Changelist
.
This results in our Commit tool window showing the changes when we click ok.
A look in the Git log also shows a change.
That commit is…gone! We’re back to where we were before the commit.
What would this have been like from the command line? Let’s take a look at the Git tool’s Console tab, to see behind the scenes. There it is, the command that we would have had to type, from the command line.
Want to learn more about Git?
Only Commit Some Changes
Select specific files or regions within files during the commit process for a lower level of commit granularity.
You’ve done a lot of work, but not all the changes should go in one commit. Let’s use partial commit.
In the commit window, look at your changes. Skip the first file by clicking the checkbox. In the second file, open the diff and deselect some of its changes.
Now when you commit -- just those parts are included. The unselected parts remain as changes.
The Problem
You sit down to do some work. It’s going well. You’re in the zone. You have an idea for some other work, something for next week. Exciting stuff, you can’t help yourself. You write it down.
You get a phone call: you forgot a change in something that you did last week. Need to make a small fix.
Back to what you were doing at first. You wrap it up.
Time to ship it, with a good commit message. But there are actually 3 units of work slotted for this commit.
Today’s work, next week’s work, and last week’s work.
Each should get separate commits. Of course, you could just do a single commit, with a commit message for each unit. Fast for you, for now. But not fast for others, trying to decipher the commit history later.
You could roll back the second two changes, then manually re-apply them. But that’s -- how shall we say -- inefficient. You could use the under-appreciated changelist (or stash) facilities.
Maybe there’s a quick and easy solution.
The Solution
What’s a partial commit? Here’s a website that explains it.
That paragraph describes exactly what we want to do. The how? Maybe a little cumbersome. Fortunately our IDEs have been putting a pretty face on this operation for a while.
Let’s return to the commit tool window and walk through committing just the work we want. First, leaving out an entire file. Just click the checkbox on any files.
Sometimes you have a big directory hierarchy of files that might have been copied in. Leaving them out is easy. Just deselect the parent.You could even go in and re-select just a couple.
Next, leaving out part of a file. Bring up the diff tool. Find the change you want to omit and click the checkbox.
If you change your mind, re-select it. This is just like the normal diff tool. You could scroll through changes in a file, between files, use the keyboard-only -- all those productivity tips apply.
When you finish, you’ll see the checkbox has a “dash”. That means it is between “checked” and “unchecked”. Think of it as “some.” You do your commit as normal. It leaves the unselected changes out of the commit, meaning they are still there.
You could continue your process to select the changes for next week’s commit, with a good commit message. Then, the changes for last week’s commit, again with a good commit message. There, you’ve processed all the changes and your commit history is easy to digest later.
Want to see what happened behind the scenes? The Git tool’s Log tab shows the commands issued. This is what you would have had to type.
Use Local History to Avoid Disaster
Use the IDE's built-in history facility to recover local changes when you haven't committed to VCS.
You’re in your repo. You add a file. Later, you make some edits, but then -- you change your mind. You want to revert but you never committed.
Use the IDE’s local history on a file… when you aren’t under version control, or you’re in between commits. Browse each IDE change, see diffs, recover from mistakes.
Delete a file by accident? Go to the folder’s local history, and recover that too!
The Problem
This is the "Oh my goodness you saved my sanity" tip.
Sometimes you are in a project that isn't yet under version control. Or, you've done a lot of work since your last commit. For example, a file is under version control, but you've been very busy.
You pause for a bit, have some inspiration, and hack away. You delete a paragraph, then ultimately finish the text. But now you want that paragraph back! Git can’t help, because you didn't commit before hacking away.
You could try “Undo-Undo-Undo-Copy-Redo-Redo-Paste.” But that’s barbaric. There has to be a better way.
The Solution
This is going be one of those things that people love about our IDEs.
Local History to the rescue. Our IDEs have a built-in facility that tracks revisions for all IDE-initiated changes -- whether you are using a VCS or not.
Right-click on a file and choose “Local History” then “Show History”. On the left, you get a list of changes detected by the IDE. When you select one, you get a diff – comparing to the current file contents – on the right.
As you go through the changes, you see each diff. Like our normal diff viewer, you can apply changes to recover portions.
Perhaps you want the entirety of the file at that point in the history. Right-click on that revision and choose revert.
If a certain revision is known to be in a certain state, right-click and apply a friendly label.
That covers changes to a file. But what if you deleted the file, and it wasn't under VCS? Go to that file’s folder and choose Local History. The deletion event is there, and you can restore the file.
As a wrapup, let’s see the same sequence -- without the mouse! First, invoke Search Everywhere and search for the Show Local History action.
In the Local History window, tab into the Old Changes panel. Cursor down to the edit. Tab to go into the changes.