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
If you want to do something, but don't remember the shortcut or menu option, use Find Action. Press ⇧⌘A (on Mac) or Control+Shift+A (on Windows/Linux)
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 of 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 and Project Tool.
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.
How to use: Control the tab placement to position where the tabs are in the IDE. Invoke Tab placement | None to hide them completely.
How to Quickly Jump to Recent Files in any JetBrains IDE
Are you tired of hunting for that crucial file buried in your project? Say goodbye to the hassle with these IDE shortcuts and tips. Jump to recent files effortlessly in JetBrains IDEs like IntelliJ IDEA, PyCharm, PhpStorm, WebStorm, GoLand, CLion, RubyMine, and more!
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.
How to use:
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.
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.
How to use:
To go Backward, ⌘[ (macOS) / Ctrl+Alt+Left Arrow (Windows/Linux).
To go Forward, ⌘] / (macOS) Ctrl+Alt+Right Arrow (Windows/Linux).
Activate Navigation Bar
Bring up the Navigation Bar as needed, let it disappear when finished.
Use the Navigation Bar to move around files, even when the whole UI is hidden away.
How to use:
Bring the Navigation Bar, ⌘↑ (macOS) / Alt+Home (Windows/Linux).
Create New File With Navigation Bar
Activate the Navigation Bar and create a new file somewhere in the project tree.
Want to create files without interrupting your flow?
Want to create a file somewhere in your project tree, without the mouse?
How to use:
Use the Navigation Bar, ⌘↑ (macOS) / Alt+Home (Windows/Linux), to get to a directory then use the keyboard to make and open a new file at the target, with ⌘N (macOS) / Alt+Insert (Windows/Linux).
Find In Path With Navigation Bar
Use keyboard and Navigation Bar to find files under a path.
Need a fast way to find files in a path, without disrupting your flow?
Closed the Project tool window and need to find a file somewhere in the project tree?
How to use:
Activate the Navigation Bar, ⌘↑ (macOS) / Alt+Home (Windows/Linux).
Then navigate to the target, and use Find in Path, ⌘⇧F (macOS) / Ctrl+Shift+F (Windows/Linux), from the keyboard.
Add Line After/Before
Smart-add a line, from the middle of a line, after or before the current line.
Language-aware line adding, no muss no fuss.
How to use: 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
Select portions of code that you need to, faster
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.
How to use:
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.
How to use:
Move Statement Up with ⌘⇧↑ (macOS) / Ctrl+Shift+Up Arrow (Windows/Linux).
Move Statement Down with ⌘⇧↑ (macOS) / Ctrl+Shift+Up Arrow (Windows/Linux).
Reformat Code
Tell GoLand to clean up indentation and other code style in your file.
Reformat Code makes it a piece of cake to fix style warnings and make your code formatted like go fmt would.
How to use:
Invoke Reformat Code via ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).
Optimize Imports
Automate the organizing and cleaning up of your Go imports with Optimize Imports.
Optimize Imports helps you deal with unsorted imports and unused imports.
How to use:
Optimize Imports is enabled by default in Reformat Code.
You can invoke it manually via ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).
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.
How to use:
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.
How to use:
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.
How to use:
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.
How to use:
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.
How to use:
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.
How to use:
Press ⌘P (macOS) / Ctrl+P (Windows/Linux) to invoke this feature.
Pro tip:
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.
Conditional Breakpoints
Speed up your debugging by stopping execution only when you want to.
Stop stepping.
Have a breakpoint in a loop and find yourself clicking Continue repeatedly? Change your breakpoint to only stop when a condition is met.
How to use:
Edit the breakpoint properties via ⌘⇧F8 (macOS) / Ctrl+Shift+F8 (Windows/Linux), then type in the Condition you want.
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?
How to use:
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.
How to use:
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.
How to use:
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.
How to use: Launch the test with Coverage support and then use the Coverage tool window to navigate to your packages/files and see their coverage.
Create a Project from GitHub
Let GoLand do the work to clone and set up a project hosted on GitHub.
From repo to project in no time.
You need to evaluate a project. You need to get a fork. You're always getting code. Let GoLand do the clone and make the project.
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 mouseover 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 Last Commit
Undo a commit...without misery.
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.
Only Commit Some Changes
Unselect files or changed regions within files during the commit process.
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 changes when VCS can't help you.
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.