Top 25 Editing Features of GoLand IDE – Part 1
Today’s post is the first one in a mini-series of posts looking at the top 25 editing features in GoLand. The best part about these features? They require zero configuration and are all built into the IDE by default, without the need to search for or install any plugins.
In case you missed our previous post about Code Completion tips, we recommend giving it a look to discover even more useful tips.
Without wasting any more time, let’s jump into the topics:
- Code generation
- Text selection
And here are the tips from the other articles in the series:
- Navigation between files
- Structure and navigation
- Clipboard operations
- General tips
Let’s start by generating code using the IDE.
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, Ctrl+I on Windows/Linux and ^+I on macOS, and then select either to generate a new type or use an existing type from the current file.
Adding tags to a structure can be done by starting to type either json or xml after the field type.
Custom Structure Tags
You can add your own structure field tag by going to Settings/Preferences | Editor | Live Templates and then selecting Go Struct Tags. Then you can either customize an existing template, duplicate it, or create a new one. To learn more about what the placeholders are, visit our help page on this topic.
Generate a test
GoLand offers the option to quickly generate a test. Invoke with Ctrl+Shift+T on Windows/Linux, Cmd+Shift+T on macOS, and select generate test from the popup. You can choose to test a function/method, the whole file, or the whole package.
Moving on, let’s manipulate the source code.
With Extend selection Ctrl+W on Windows/Linux and⌥↑ on macOS, you can quickly select parts of your code using semantic knowledge about it.
Extend selection is complemented by the Shrink Selection, Ctrl+Shift+W on Windows and Linux, and ⌥↓ on macOS, which lets you shrink the selection made using the same semantic knowledge of the source code.
Multiple selections is a very powerful feature in the editor that lets you quickly select and edit multiple pieces of code at once.
Select something as you normally would, or press Alt+J on Windows and 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 on Windows/Linux, ^+G on macOS, again to go forward further, or Shift+Alt+J, Shift+^+G on macOS, to go back. When the search reaches the end of the file, it will start over again from the beginning.
Select all occurrences in a file
Do you want to select all the occurrences of a piece of code? Then simply press Ctrl+Alt+Shift+J on Windows/Linux, and Cmd+^+G on macOS.
After the selection is complete, you can start editing all the fragments as if they were all the same one.
Just to remind you, 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.
That’s it for today’s post. While we present just 7 features from our list, we think that these will come in handy to any developer, new or experienced, and will increase your productivity.
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.