Editing Tips & Tricks
Learn some of the most useful Editing features of GoLand.
Editing code is a frequent activity that programmers do. However, editing is not only about typing the code but also navigation in a code-base.
If IDEs are good at one thing, is that they can help automate various tasks, including writing that tedious boilerplate code.
In this playlist we're going to have a look at many of the code editing features in GoLand, and how to effectively use them.
Implement an interface
Implementing an interface is a common task that Go programmers need to do
GoLand offers the option to quickly implement an interface using the Implement methods action.
How to use:
Ctrl + I on Windows/Linux or ^ + I on macOS, (capital i on all shortcuts), and then select either to generate a new type or use an existing type from the current file.
New in 2017.3
Structure tags
Quickly add tags to any fields from structures
GoLand helps you add struct tags using custom live templates built into the IDE.
How to use:
Adding tags to a structure can be done by starting to type either json or xml after the field type.
New in 2017.3
Custom Structure tags
Add custom tags to any fields from structures
GoLand has a few Live Templates builtin for struct tags, such as json or xml.
How to use:
You can add your own structure field tag by going to Settings/Preferences | Editor | Live Templates and then select Go Struct Tags.
Then you can either customize an existing template, duplicate it, or create a new one.
New in 2017.3
Generate a test for an element
Automate test generation
GoLand offers the option to quickly generate a test.
How to use:
Invoke with Ctrl + Shift + T on Windows/Linux, ⌘ + ⇧ + T on macOS, and select Test for ... from the popup.
You can choose to test a function/method, the whole file, or the whole package.
New in 2017.3
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 Ctrl + W on Windows/Linux and ⌥ + ↑ on macOS, to use Extend Selection.
Shrink Selection has a similar shortcut, Ctrl + Shift + W on Windows/Linux and ⌥ + ↓ on macOS.
New in 2017.3
Multiple selections
Select multiple items faster
Multiple selections is a very powerful feature in the editor, that lets you quickly select and edit multiple pieces of code at once.
How to use:
Select something as you normally would, or press Alt + J on Windows/Linux, ^ + G on macOS, to select the symbol at the caret.
GoLand will search through the current file until it finds a matching piece of text, which it then adds to the selection.
You can press Alt + J again to go forward further, or ⇧ + Alt + J to go back. When the search reaches the end of the file, it will start over again from the beginning.
New in 2017.3
Select all occurrences in a file
Quickly select all occurrences of a piece of text in the current file
Do you want to select all the occurrences of a piece of code?
How to use:
Press Ctrl + Alt + Shift + J on Windows/Linux, and ⌘ + ^ + G on macOS.
After the selection is complete, you can start editing all the fragments as if they were all the same one.
Pro tip:
If you plan to use this feature to rename something, then you should have a look at our Rename refactoring, which is designed to work safely across multiple packages, not just at the file level, with full preview and undo support.
New in 2017.3
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 Ctrl + Shift + N on Windows/Linux, ⌘ + ⇧ + O on macOS to invoke the Navigate to file pop-up.
Pro tip:
As a hidden gem, try finding a directory by name.
New in 2017.3
Navigate between opened files using the Switcher
Don't use the mouse to quickly move between multiple files
The Switcher allows you to quickly move between open files during your editing session.
How to use:
Invoke the Switcher using Ctrl + Tab on Windows/Linux or ^ + Tab on macOS.
Pro tip:
You can use it to quickly switch between the previous file and the current one using the shortcut.
If you want to browse the whole list, use the shortcut and hold Ctrl on Windows/Linux or Shift on macOS. You will be able to use Ctrl + Tab on Windows/Linux or ^ + Tab on macOS again to move forward through the list of options, or press Shift + Tab and move backward.
New in 2017.3
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!!
Recent Locations
Jump back and forth between files using code snippets you've recently seen
The Recent Locations pop-up allows you to search for a specific change or recently viewed piece of code.
How to use:
Invoke it using Ctrl + Shift + E on Windows/Linux, ⌘ + ⇧ + E on macOS, and the list of recently viewed files will display not only the file name but also the code snippets around the area last viewed in the file.
Pro tip:
Invoke the same shortcut again, and only the changed files will be visible.
The best part? Speed Typing works here: you can type in code to filter the results further.
New in 2019.1
Jump to the Navigation Bar
Get an overview of your current location, and the project itself
The Navigation Bar has a useful feature that can help you get an overview of both your current location and the structure of the project itself.
How to use:
Press Alt + Home on Windows/Linux, ⌘ + ↑ on macOS, and it will appear.
Use the Arrow keys to move around inside and press Enter to enter a certain folder or Esc to exit from it.
Pro tip:
Speed Search is available here and it will help you quickly filter the files in your view.
New in 2017.3
Structure popup
View the file or whole package structure and navigate to any element
The File Structure popup window allows you to get an overview of all the elements defined in a file or a package.
You can use it to navigate to any definition and invoke it from anywhere.
How to use:
Use Ctrl + F12 on Windows/Linux or ⌘ + F12 on macOS, and a window with all the elements defined in the current file will show up.
Pro tip:
Press Ctrl + F12 on Windows/Linux or ⌘ + F12 on macOS, again with the window still open, and it will show all the elements defined in the package of the current file.
Speed Typing can then help you to narrow down the list of elements to the one that you need.
New in 2017.3
Select in
Select the current file in the Project or Changes view and more
The Select in... action helps you select the currently selected file in a particular tool window.
It works in places such as the Project or the Changes view tool windows, and even in Explorer/Finder
How to use:
Press Alt + F1 on Windows/Linux or ⌥ + F1 on macOS.
New in 2017.3
Go to/from a test
Navigate to and from a test subject like a method or function
Use the Navigate | Test feature to quickly go to a test for an element.
How to use:
Press Ctrl + Shift + T on Windows/Linux, ⌘ + ⇧ + T on macOS.
Pro tip:
Press the same shortcut on a test and you'll be able to jump back to the element that is the subject of the test.
New in 2017.3
Type Hierarchy
Discover what types implement an interface or what interfaces are implemented by a type
The Type Hierarchy feature allows you to answer questions such as "What interfaces a type implements?" or "What the types are that implement an interface?"
How to use:
Invoke it using Ctrl + H on Windows/Linux, ^ + H on macOS.
Pro tip:
You can dig deeper through the list of hierarchy to get as much information as you need.
New in 2017.3
Call Hierarchy
Analyze call trees for functions or methods
Call Hierarchy allows you to quickly see all the places where a function or method is used.
How to use:
Press Ctrl + Alt + H on Windows/Linux, ⌥ + ^ + H on macOS, and the Call Hierarchy tool window will open up with all the places that the function is called inside.
Pro tip:
This works for interface methods, type methods, methods, and calls.
You can then drill down into the call chain to see where those other functions are called.
Speed Typing is available to help you quickly navigate to the element you need.
New in 2017.3
Show usages
Quickly discover the usages of the element your cursor is at
The Show usages feature allows you to quickly answer the question "Where's this element used?"
It will open a pop-up that you can quickly use to navigate/filter or otherwise dismiss with the results you are looking for.
How to use:
Press Ctrl + Alt + F7 on Windows/Linux, ⌥ + ⌘ + F7 on macOS.
New in 2017.3
Compare with clipboard
Compare text, files or directories and even use the clipboard contents
GoLand has a built-in diff viewer for code, revisions, and even images.
How to use:
Select any pair of files and press Ctrl + D on Windows/Linux and ⌘ + D on macOS.
Pro tip:
To quickly compare the editor with the clipboard, choose View | Compare with Clipboard.
If you have selected a single file, the IDE will prompt you to select another file to compare it to.
New in 2017.3
Paste from history
Paste from the clipboard even if it's not the last item you copied into it
The Paste from History feature you to use the (limited) history of everything you put in the clipboard.
How to use:
Press Ctrl + Shift + V on Windows/Linux and ⌘ + ⇧ + V on macOS to open pop-up window.
New in 2017.3
Switch to the editor
Get the focus back to the editor regardless what is currently focused
There are a lot of (tool) windows opening or appearing when using the IDE.
How can we quickly get back to the editor?
We can press the Esc key, and the focus will switch back to the editor.
The tool window you're switching from will preserve its visibility state in this case.
New in 2017.3
Hide all tool windows
Hide all the tool windows in the IDE
You can hide all the tool windows in the IDE and quickly switch to the editor via Ctrl + Shift + F12 on Windows/Linux, or ⌘ + ⇧ + F12 on macOS.
New in 2017.3
Speed typing
Quickly navigate to or filter any list of items in the IDE
Speed Typing is the ability to type anything in a list and have the results filtered.
You can then use the arrow keys to move through the list, or press Esc to dismiss the filter.
New in 2017.3
How to Search Everywhere in Any JetBrains IDE
Use ⇧⇧ (macOS), or Shift+Shift (Windows/Linux), to bring up the Search Everywhere dialog. You can search across Classes, Files, Symbols and Actions.
The Problem
How do I find stuff, without memorizing a bunch of stuff? You’re editing something. You want to jump to something in your project. The IDE has so many options. What’s the fastest way?
You could browse through the file tree to find the file. Similarly, activate the navigation bar and wander around. Lots of other choices: Recent Files, Recent Locations, bookmarks, keeping a thousand tabs open.
The Solution
Press Shift-Shift for Search Everywhere. The one IDE entry point to find everything. Type a string, make a selection, and jump to the target.
To dismiss the popup, press Escape. You can jump to a file by putting in the name of a file, not something in the file. You can type parts of a file path, to save some time. Those tabs show the kinds of things that can be searched. Hit tab to go Classes, then again to go to Files.
Mouseover on the tabs to show key bindings to open directly. “Symbols” is a favorite. Actions…the next tip. Want more power? Here’s three bonus tips:
- This checkbox controls how widely Search Everywhere goes looking. Press Shift-Shift again to toggle it to checked, then again to unchecked.
- Use filter… to restrict results by certain criteria, per-tab.
- Click “Open in Find Tool Window” to get the full “find” treatment.
Yes, you can resize this window, as if it was a normal window. Next time you use Search Everywhere, it will remember the dimensions. Last point: the footer area has…tips! As you can see from these, lots of power in Search Everywhere.
Here’s one you didn’t see coming: Search Everywhere is also a desktop calculator.
Search Everywhere is the perfect first thing. Super-easy to learn, immediately useful, and gradually scales to more power.
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. And – on Mac – Ctrl-Cmd-Right arrow
to accept changes.