Top 25 Editing Features of GoLand IDE – Part 2
In today’s article, we continue the series about the Top 25 editing features of the IDE that will boost your productivity. The previous post can be found here.
- Navigation between files
- Structure and navigation
And here are the tips from the other articles in the series:
- Code generation
- Text selection
- Clipboard operations
- General tips
Let’s start with today’s tips!
Navigation between files
As source code is usually split across multiple files, navigation among them might not always be easy.
GoLand has a few features that can help us perform this task quicker.
Navigate to file
First, we have the Navigate to file feature, Ctrl+Shift+N on Windows/Linux, ⌘⇧O on macOS, which allows us to search for a file by name, even if we know only part of it. As a hidden gem, try finding a directory by name.
You can use the same shortcut to search for a file in the current project only, your source code only, or all places, which means you can search in other places like Go Modules dependencies and GOROOT.
Navigate between opened files using the Switcher
Since you’ll likely be opening files, lots of them, during an editing session, how can you quickly switch between them? The Switcher, Ctrl+Tab on Windows/Linux, ^Tab on macOS, is here to help you. You can use it to quickly switch between the previous file and the current one using the shortcut.
Alternatively, use the shortcut but then hold Ctrl on Windows/Linux, ^ on macOS, and you will be able to use Tab again to move forward through the list of options, or press Shift+Tab and move backward.
Do you want to do this even faster? Then press Ctrl+E on Windows/Linux, ⌘E on macOS, to bring up the Recent Files window. This allows you to quickly navigate around the same list. Here you can use the Speed Typing feature, to filter it to see only what you want to see.
If you press the same Ctrl+E on Windows/Linux, ⌘E on macOS, shortcut while the Recent Files window is open, then the list will become more useful and display only the files that have been changed recently.
The Recent File window is great, especially with the filter to view only the changed files. But it is not enough if we are searching for a specific change or piece of code we recently viewed. After all, we can’t and shouldn’t always remember which file a certain part of our code is in.
This is where the Recent Locations popup comes in.
Invoke it using Ctrl+Shift+E on Windows/Linux, ⌘⇧E, 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.
Invoke the same shortcut again, and only the changed files will be visible. And the best part? Speed Typing works here: you can type in code to filter the results further.
Structure and navigation
Working with any source code is not about writing or reading only. Navigation is an important part. Let’s see how GoLand makes navigation easy, regardless of project size.
What if you are in a file, and you quickly want to jump to a certain definition? You could invoke the Find feature, which would work, as long as you remember the type of that element. But what if you don’t, or what if it’s a new code base that’s not yet familiar to you, then the File Structure popup window has your back.
Use Ctrl+F12 on Windows/Linux, ⌘F12 on macOS, and a window with all the elements defined in the current file will show up. Press Ctrl+F12 on Windows/Linux, ⌘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.
Jump to the Navigation Bar
Regardless of whether you keep it displayed or not, 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.
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.
As you have probably guessed already by now, Speed Search is available here as well, and it will help you quickly filter the files in your view.
What if you need to select the currently selected file in a particular tool window, e.g. the Project or the Changes view, or even Explorer/Finder? This is where the Select in… action, available via Alt+F1 on Windows/Linux, ⌥F1 on macOS, comes in handy:
Go to/from a test
Quickly going to a test for an element can be useful to investigate how that element should be used. Press Ctrl+Shift+T on Windows/Linux, ⌘⇧T on macOS, and you’ll be able to jump to the test for an element. Press it again, and you’ll be able to jump back to the element that is the subject of the test.
Have you ever wondered what interfaces a type implements? Or what the types are that implement an interface? The answer to these questions is the Type Hierarchy feature, invoked via Ctrl+H on Windows/Linux, ^H on macOS, which allows you to quickly show both the types that implement an interface and the interfaces implemented by a type. And you can dig deeper through the list of hierarchy to get as much information as you need.
If you want to quickly see all the places where a function or method is being used, then Call Hierarchy is the feature you are looking for.
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. You can then drill down into the call chain to see where those other functions are called.
This works for interface methods, type methods, methods, and calls.
And of course, Speed Typing is again available to help you quickly navigate to the element you need.
A question that often comes up when working with code is: where’s this element used? GoLand has the Find usages action, Alt+F7 on Windows/Linux, ⌥F7 on macOS, to help you out with that.
But what about not having a tool window for this, but rather a popup that you can quickly use to navigate/filter or otherwise dismiss? That’s where GoLand comes in with the Show usages feature, accessible via Ctrl+Alt+F7 on Windows/Linux, ⌥⌘F7 on macOS,.
That’s it for today’s post. We’ve seen 11 features from our list, all designed to improve productivity and assist you in navigating around your codebase. Have you discovered a new one? Which one is your favorite?
Subscribe to Blog updates
Does Machine Learning in Go Have a Future?
In this article, you'll explore the challenges of actively using Go for Machine Learning.
OS in Go? Why Not?
In this article, you'll learn why languages like C have a stronghold over OS development and whether writing an OS using Go is possible.
Comparing database/sql, GORM, sqlx, and sqlc
This article compares the database/sql package with 3 other Go packages, namely: sqlx, sqlc, and GORM. The comparison focuses on 3 key areas – features, ease of use, and performance.