Zig Code Flow
A comprehensive VS Code extension providing Zig language support with powerful snippets to enhance your Zig development experience. As we all know, writing zig code can sometimes be tedious, as there are a lot of long common patterns. Who remembers how to properly create an allocator? This extension tries to cover your back by providing you with the most common patterns we experience while developing.
Features
📝 60+ Zig-specific code snippets covering all common patterns
Snippet Categories
- 🔧 Basic language constructs
- 🏗️ Functions and data structures
- 🔄 Control flow and error handling
- 📚 Memory management utilities
- ✅ Testing helpers
- 🛠️ Development tools
Learn more about available snippets in the sections below.
Table of Contents
Installation
From the Marketplace
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "Zig Code Flow"
- Click Install
- Rate 5 stars!
Manual Installation
- Download the latest release from the GitHub repository
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Click on the three dots in the top right corner
- Select "Install from VSIX..."
- Choose the downloaded file
- Rate 5 stars!
Snippets
Basic Snippets
Prefix |
Description |
ziglove |
Prints 'I love ZIG!' to the console |
zighello , helloworld |
Prints 'Hello, World!' to the console |
launch , startup |
Initializes a main function |
project , template |
Creates a new project template |
import |
Import a module using @import |
import_std , imps |
Import the standard library |
import_builtin , impb |
Import the builtin module |
Functions
Prefix |
Description |
fn |
Create a function with optional error union return type |
fn_generic |
Create a generic function with compile-time type parameter |
pub_fn |
Create a public function with optional error union return type |
inline_fn |
Create an inline function |
nested_fn |
Create a nested function inside a struct |
Debug
Prefix |
Description |
debug |
Print debug output using std.debug.print |
stdout |
Get the standard output writer |
Variables
Prefix |
Description |
comptime |
Define a compile-time variable |
var |
Declare a variable with explicit type |
const |
Declare a constant with inferred type |
const_type |
Declare a constant with explicit type |
Data Structures
Prefix |
Description |
struct |
Create an anonymous struct |
const_struct |
Create a named struct type |
enum |
Create an enumeration with specified integer type |
union |
Create a tagged union type |
Loops
Prefix |
Description |
for_value |
Create a for loop iterating over values |
for_value_index |
Create a for loop with both value and index |
for_inline |
Create an inline for loop |
for_label |
Create a labeled for loop |
for_else |
Create a for loop with else branch |
while |
Create a while loop |
while_else |
Create a while loop with else branch |
while? |
Create a while loop for optional values with error handling |
while_label |
Create a labeled while loop with nested break |
while_inline |
Create an inline while loop |
Array and Lists
Prefix |
Description |
list |
Create an anonymous list literal |
array_init |
Initialize an array with optional sentinel |
array_list |
Create a dynamic array list |
fixed_array_list , array_list_length |
Create an array list with fixed capacity |
append |
Append an element to an array list |
append_assume_capacity |
Append an element to an array list assuming there is enough capacity |
to_owned_slice |
Convert ArrayList to owned slice |
string_hash_map |
Create a hash map with string keys |
sort |
Sort slice using std.sort |
Memory Management
Prefix |
Description |
GPA , general_purpose_allocator |
Initialize a General Purpose Allocator (GPA) |
arena_allocator |
Initialize an Arena Allocator |
FBA , fixed_buffer_allocator |
Initialize a Fixed Buffer Allocator (FBA) |
Control Flow
Prefix |
Description |
if |
Create an if statement |
if_else |
Create an if-else statement |
if_else? |
Create an if-else for optional values with error handling |
switch |
Create a switch statement |
orelse |
Handle null with orelse return |
Error Handling
Prefix |
Description |
try |
Try an expression that may return an error |
catch |
Catch and handle errors from an expression |
defer |
Create a defer block |
errdefer |
Create an errdefer block |
error |
Create an error value |
error_set |
Define an error set |
Random
Prefix |
Description |
randint |
Generate a random integer |
Testing
Prefix |
Description |
test |
Create a test block |
expect |
Add a test expectation using std.testing |
Assembly
Prefix |
Description |
asm |
Insert inline assembly code |
Prefix |
Description |
filename |
Insert current file name with extension |
filenamebase |
Insert current file name without extension |
directory |
Insert current directory path |
abspath |
Insert absolute path of current file |
relpath |
Insert workspace-relative path of current file |
workspacename |
Insert current workspace name |
workspacefolder |
Insert current workspace root folder path |
Random values
Prefix |
Description |
randomvalue |
Insert random number |
randomhex |
Insert random hexadecimal value |
uuid |
Insert a UUID (Universal Unique Identifier) |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add some amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
Support
If you find any bugs or have feature requests, please open an issue on the GitHub repository. If you find any secrity vulnerabilities, please contact me directly at contact@gaskam.com.
Acknowledgements
- Thanks to the Zig team for creating such an amazing language.
- Thanks to Kamil Leys for his friendly advice and support.
- This extension is inspired by the Zig Snippets in some parts.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Coded with ❤️ by Gaskam
See other projects on our GitHub page.
You can also visit our personal GitHub profiles: