What is Odin?
Odin is a general-purpose programming language with distinct typing built for high performance, modern systems and data-oriented programming. Odin is the C alternative for the Joy of Programming.
What is Zed?
Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter. It’s also open source.
How to write and run Odin programs in Zed?
The following instructions describe how to use Zed code editor and its tasks feature to easily run programs written in Odin from within the editor.
Note: I am using Zed installed in Ubuntu.
-
Install the Odin extension to enable Odin language support (syntax highlighting, code completion, etc.)
-
Create
.zed
folder in your projects folder. -
Create
tasks.json
file in the.zed
folder. -
Add the following configuration to
tasks.json
:[ { "label": "Run", "command": "odin run .", "reveal": "never" } ]
Note: The last line (
"reveal": "never"
) is optional but it allows to keep focus in the editor. Technically, there is a dedicated setting"hide"
that should hide the terminal tab after the task finishes but it does not seam to work properly. The only drawback of using the"reveal": "never"
setting is that the “Run” tab will not get focus if there are other terminal tabs already opened. -
[Optional] You can add different tasks like build, debug, test, etc. to the
tasks.json
. See the tasks docs for more details. Below is an example for the excelent hot reload flow by Karl Zylinski.[ { "label": "Hot Reload", "command": "./build_hot_reload.sh", "reveal": "never", "hide": "always" }, { "label": "Run", "command": "./game.bin", "reveal": "never", "hide": "always" }, { "label": "Build Debug", "command": "./build_debug.sh" }, { "label": "Build Release", "command": "./build_release.sh" } ]
-
Restart Zed. Without this step, some of the settings do not work as expected.
-
Now you can run the task using one of the following ways:
- “task: spawn” (
alt-shift-t
) command from the command palette (F1
,ctrl-shift-p
or:
in vim mode). alt-p
to re-run the last task.- You can also create a custom key bindings and assign different keys for each task:
Again, you must restart Zed (or at least reload project) to fully apply the changes.
{ "context": "Workspace", "bindings": { "shift-f10": ["task::Spawn", { "task_name": "Hot Reload" }], "ctrl-shift-r": ["task::Spawn", { "task_name": "Run" }] } }
- “task: spawn” (
Enjoy coding in Odin in Zed!