How to run go commands from the editor
This guide shows how to format, vet, build, test and run your project without leaving Turbo Go. It assumes the editor is installed and you have a Go project.
Get a starter file
Start the editor from the project's own directory, then choose Go ▸ Create tools file (Alt-G, then C).
That writes .turbo-go/tools.toml with the five commands a Go project runs before it commits, and opens it:
[[tool]]
name = "~F~ormat"
command = "gofmt -l -w ."
output = "popup"
[[tool]]
name = "~T~est"
command = "go test ./..."
output = "popup"
[[tool]]
name = "~R~un"
command = "go run ."
# A terminal, not a popup: a program that reads the keyboard has to be able to
# be answered, and one that runs long has to be able to be interrupted.
output = "terminal"
Each [[tool]] becomes one line of the Go menu, in the order they appear — unless it names a menu of its own, which the next-but-one section covers. The file is read every time the menu opens, so an edit takes effect immediately.
Run one
Alt-G, then the letter between the tildes — F to format, T to test.
A popup opens at once and fills in as the command runs. Its title carries the command and, once it has ended, how it went:
┌──────────── go vet ./... — exit 1 ────────────┐
│ main.go:6:2: unreachable code │
│ │
│ [ Close ] │
└───────────────────────────────────────────────┘
| Key | Effect |
|---|---|
↑ ↓ PgUp PgDn Home End |
Read through the output |
Escape |
Close it — and stop the command if it is still running |
Enter |
Close it |
A command that succeeded silently shows (no output) rather than a blank box, so you can tell it from one that has not started.
The popup follows the output as it arrives until you scroll back, and then leaves you where you are.
Choose where the output goes
Set output on a tool:
output |
What you get |
|---|---|
popup |
A dialog that fills in as it runs. The default. |
terminal |
A terminal window: colours, Ctrl-C, and the keyboard reaches the program |
editor |
An editing window once it has finished, to search with Ctrl-F |
Run is terminal in the starter file, and it is the example of why the key exists: a popup cannot answer a program that reads from the keyboard, and cannot be interrupted with Ctrl-C.
Reach for editor when the output is something to work through — a long go test -v, or a coverage report you want to search.
A long command holds the editor
A popup is modal: while go build runs, you cannot type anywhere else. Escape closes it and stops the command.
If that gets in the way for a particular command, give it output = "terminal" — the window is an ordinary one and you can carry on working beside it. That is what making the key configurable is for.
What happens to your open files
Format rewrites files on disk — including the one you are looking at. When a command finishes, the editor re-reads every open file that has no unsaved changes, so the formatted version appears without you doing anything. The status bar says how many.
A file with unsaved changes is left alone, and the status bar says so too:
Reloaded 2 files; 1 file with unsaved changes left alone
That is deliberate: your edit and the formatter genuinely disagree, and the editor is not the one that should decide which wins. Save first (F2) and run the command again, or keep editing and format later.
Add your own commands
Edit .turbo-go/tools.toml. A command goes to sh -c, so one entry can be a whole sequence:
[[tool]]
name = "~C~heck"
command = "gofmt -l -w . && go vet ./... && go test ./..."
output = "popup"
[[tool]]
name = "Tid~y~"
command = "go mod tidy"
output = "popup"
[[tool]]
name = "Cover~a~ge"
command = "go test -coverprofile=cover.out ./... && go tool cover -func=cover.out"
output = "editor"
Give each a hot key with tildes, and keep them distinct — the menu answers the first match it finds.
Put a tool in a menu of its own
A tool that has nothing to do with Go does not belong in the Go menu. Give it a menu:
[[tool]]
name = "~E~cho"
command = "echo TADA"
output = "terminal"
menu = "Tools"
[[tool]]
name = "~U~p"
command = "docker compose up -d"
menu = "Docker"
[[tool]]
name = "~D~own"
command = "docker compose down"
menu = "Docker"
That gives you a Tools menu and a Docker menu on the bar, between Go and Help, in the order the names first appear in the file. Docker holds both its tools. Nothing needs restarting: save the file and the bar follows.
The name is yours to choose — there is no list to pick from. Leave menu out and the tool stays in Go, which is where all five starter commands are.
The hot key is chosen for you
You cannot know, when writing the file, which letters the editor's own menus have taken. So it works it out: the first letter of the name that nothing else claims gets the tildes.
Tools gets Alt-T. Format gets Alt-M, because F is File's, o is Options' and r is Run's.
Write the tildes yourself — menu = "Doc~k~er" — and a free letter is kept. A taken one is not: the bar answers the first menu matching a key, so honouring your choice would make one of the two menus unreachable. It picks another letter and says nothing.
Variants
- You want
golangci-lintinstead ofgo vet. Change theLintcommand.go vetis the default because it ships with the toolchain and is never missing; anything else you have to install. - You started the editor from a subdirectory. Commands run there, so
./...covers only that subtree. Start from the project root. - The file has a mistake in it. The menu shows a greyed-out
Cannot read toolswhere the commands would be, and Create tools file is still there. - A command is not installed. The popup shows
command not foundand— exit 127, which is what a shell would have said. - You want a menu named after one that exists.
menu = "File"gives you a second File menu, further along the bar, with a different hot key. Nothing stops you; nothing recommends it either. - Your menu has no hot key. Every letter in its name was already taken.
F10and the arrow keys reach it, and so does the mouse. Rename it to something with a free letter. - You misspelt
output's value. The whole file is refused and the menu saysCannot read tools, naming the tool and listing what it could have been. A silent fallback would have sent the output somewhere you did not ask for.
Ask for a value when the command runs
Some commands need something typed each time: a module path, a crate name, a test to filter on. Put a {{label}} where the value goes:
[[tool]]
name = "~I~nit module"
command = "go mod init {{module path}}"
output = "popup"
Choosing it now opens a box titled Init module with one field, labelled module path. Type the value and press Enter; the command runs with it. Escape, and nothing runs.
The value is quoted, so a path with a space in it stays one argument.
Several values at once
One field each, in the order they appear:
[[tool]]
name = "~C~opy"
command = "cp {{from}} {{to}}"
Tab moves between the fields, Enter runs it.
One field standing for several arguments
Quoting is wrong when you mean "put these flags on the end". Add ... inside the braces and the value goes in verbatim:
[[tool]]
name = "Test ~o~ne"
command = "go test {{extra flags...}} ./..."
Type -run TestParse -v and all of it reaches the command as separate arguments.
The same value twice
Write the label twice; you are asked once:
[[tool]]
name = "~N~ew directory"
command = "mkdir {{name}} && cd {{name}}"
Variants
- The value is the same most times. Run it once and the box remembers what you typed, for the rest of the session. It is not written to disk.
- Your command has braces in it already.
awk '{print $1}'andfind . -exec rm {} +are left alone: only double braces ask for anything. - The command asks for more values than fit on screen. The editor says so rather than opening a box whose OK button is below the bottom of the terminal. Make the terminal taller, or split the command into two tools.
See also
- Every key of the file and every rule: Go tools reference
- Why each command gets a terminal window, and why an unmodified file reloads: Go tools
- The windows the commands run in: Terminal windows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|