Skip to content
nim-style-guide logo

Preamble

nim-style-guide

Write clear, consistent Nim code in a simple stdlib-aligned style, covering imports, naming, proc vs func vs template choices, local variables, constructors, formatting, and control flow. Use when writing new Nim code or reviewing a Nim module for readability, consistency, and low-noise style dec...

planetis-m/skills0installs59stars

SKILL.md

Full skill instructions

Preamble

Use this skill to keep Nim code simple, consistent, and easy to scan. Larger examples live under references/.

Rules

Formatting

  • Indent with 2 spaces. Do not use tabs.
  • Wrap long lines before they become hard to scan.
  • Do not align columns with extra spaces.
  • Use a..b unless spaces are needed for clarity.
  • Indent wrapped declarations, calls, and conditions one extra level.

Imports And Naming

  • Prefer std/​... imports for stdlib modules.
  • Group broad stdlib imports with import std/[a, b, c].
  • Use from std/​foo import bar, baz when you only need a small API slice.
  • Types use PascalCase.
  • Procs, funcs, iterators, templates, vars, and fields use camelCase.
  • Use normal word casing such as parseUrl and httpStatus.
  • For non-pure enums, prefix values such as pcFile. For pure enums, use PascalCase.

Proc, Func, Template, Macro

  • Default to proc.
  • Use func for pure helpers and pure accessors when checked purity helps.
  • Use template only for tiny substitutions or tiny syntax wrappers.
  • If a helper has its own control flow or mutable local state, make it a proc or func.
  • Prefer proc and func over method. Use method only when you need runtime dispatch.
  • Prefer top-level helpers for reusable logic.
  • Use a nested proc when the logic is truly local or when you want a closure.
  • A nested proc may capture outer locals. If a nested proc must stay non-capturing, mark it {.nimcall.}.
  • Use macro only when syntax transformation is required.

Calls, Locals, And Types

  • Prefer compact wrapped calls over one-argument-per-line call blocks.
  • Use UFCS when it reads like an accessor.
  • Use let by default.
  • Use var only for values that mutate.
  • Keep local declarations close to first use.
  • Keep type blocks at module scope.
  • Group related fields with the same type when it improves readability.
  • When using object constructors, set the fields you want to override and omit the fields that should keep their defaults.

Whitespace Sensitivity

Nim is whitespace-sensitive in three specific places. Violating any of these produces compile errors.

  • No space before [ in type annotations.

    • array[0..4, bool] compiles. array [0..4, bool] does not.
    • The same applies to seq[string], Table[string, int], etc.
  • No space between a proc name and ( when calling with 2+ arguments.

    • foo(1, 2) passes two int arguments.
    • foo (1, 2) passes a single (int, int) tuple. Nim treats the parenthesized comma-list as a tuple constructor.
  • Spaces required around .. and ..< in slice and range expressions.

    • 0 .. high(s) and 0 ..< s.len are correct.
    • 0..high(s) may fail in some contexts (notably range[0..<n] does not compile; use range[0 .. n-1] instead).

Line Continuation

Nim has no line-continuation character. A statement continues to the next line when the current line ends in:

  • an operator (and, or, +, &, etc.)
  • a comma ,
  • an opening bracket (, [, {

The continued line must be indented further than the statement that started it.

Control Flow

  • Prefer straightforward if/​elif/​else and explicit loop conditions.
  • Tiny predicate or search helpers may use early return.
  • In stateful or multi-step procs, keep one clear normal path and use result = ... when that reads more clearly.
  • Use early return for real guard exits or found values, not as the default shape of every branch.
  • Do not use continue. Restructure the branch instead.

Workflow

  1. Pick the callable kind. Start with proc. Switch to func only for pure helpers. Use template or macro only when substitution or syntax shaping is the point. Do not use method unless you need runtime dispatch.
  2. Write imports and names. Use std/​... imports, narrow imports when practical, and keep names in normal Nim casing.
  3. Shape the control flow. Keep one obvious normal path. Use guard returns only when they make the code simpler.
  4. Clean up locals and constructors. Use let by default, keep locals near first use, keep reusable helpers at module scope, and let constructors keep declaration defaults unless you are overriding them.
  5. Remove noise. Remove unused imports, dead helpers, column alignment, and stretched call formatting.

Common Mistakes

MistakeWhy it is wrong
Using method as the default callable kindIt adds runtime dispatch where a plain proc or func would usually be clearer.
Hiding reusable helpers inside another procIt makes the helper harder to reuse and easier to turn into an accidental closure.
Using template for general helper logicIt hides normal control flow and expands code in place.
Using proc for an obviously pure helperIt loses a useful compiler-checked purity signal.
Writing one argument per line by defaultIt adds vertical noise without adding structure.
Using var for values that never mutateIt hides which locals actually change.
Turning every branch into an early return in a multi-step procIt makes the normal path harder to scan.
Using continueIt usually means the branch can be written more clearly.
Restating every object field in a constructorIt adds noise and can hide which fields are intentionally overridden.

References

  • references/​core_patterns.md: Simple default patterns for imports, callable kinds, wrapping, locals, and constructors.

Changelog

  • 2026-04-09: Created as a standalone opinionated style guide.
  • 2026-04-11: Added func purity contract guidance.
  • 2026-04-20: Added whitespace sensitivity and line continuation rules.

More skills from planetis-m

tts-tool logo
planetis-m/tts-tool

tts-tool

Generate a natural-sounding `.opus` audio file from text or markdown. Use when a user wants spoken audio, especially for content with markdown, URLs, formulas, paths, or technical notation that should be rewritten for speech.

3 0
View
nim-api-design logo
planetis-m/skills

nim-api-design

Design clear public Nim APIs for libraries and modules, including exported types, constructors, lookup functions, error contracts, and container-style interfaces. Use when creating or reviewing a Nim library API, designing an exported module surface, or deciding how callers should construct, acce...

59 0
View
ocr-tool logo
planetis-m/ocr-tool

ocr-tool

Extract raw text from PDF files with OCR, including full-document extraction, selected page ranges, and reuse of cached pages. Use when a user asks to OCR a PDF, extract text from a scanned PDF, or read selected PDF pages.

1 0
View
nim-c-wrappers logo
planetis-m/skills

nim-c-wrappers

Turn low-level C FFI bindings into an idiomatic Nim API, with safer types, cleaner module boundaries, resource management, callbacks, enums, bitflags, and exception-based error handling. Use when building a high-level Nim wrapper around a C library or improving the usability of existing raw bindi...

59 0
View
rag-tool logo
planetis-m/rag-tool

rag-tool

Store and search text or markdown as semantic chunks in a reusable local vector store. Use when a user wants to ingest documents or retrieve relevant passages from previously stored material.

1 0
View
study-assistant logo
planetis-m/study-assistant

study-assistant

Study assistant workflow for turning provided study material into exam-focused deliverables such as verbatim transcriptions, study notes, lecture-style explanations, ELI5 explanations, flashcards, Mermaid mind maps, quizzes, and essay questions.

5 0
View
nim-code-organization logo
planetis-m/skills

nim-code-organization

Organize Nim code into clear modules and multi-step workflows, with explicit state, top-level helper procs, narrow exports, and easy-to-follow orchestration. Use when refactoring a large Nim file, splitting logic across modules, designing parser-style stateful code, or cleaning up nested helpers ...

59 0
View
nim-ownership-hooks logo
planetis-m/skills

nim-ownership-hooks

Implement and review Nim ARC/ORC ownership hooks for types that manually manage resources, including move-only, deep-copy, refcounted, and copy-on-write patterns. Use when a Nim type owns pointers, buffers, file descriptors, or custom heap memory and you need correct `=destroy`, `=copy`, `=dup`, ...

59 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View