feat: first-class template file support #259

Closed
opened 2026-02-27 00:20:45 +00:00 by barrettruth · 0 comments
barrettruth commented 2026-02-27 00:20:45 +00:00

Problem

Every competitive programmer uses a personal template (standard library includes, macros, typed aliases, I/O optimization). cp.nvim's setup_code hook lets users insert template content programmatically, but it requires writing Lua code — a higher bar than pointing to a file. Tools like cf-tool and competitest.nvim support a simple template_path string per language.

Proposed solution

Add a template key per language in the language config:

languages = {
  cpp = {
    extension = "cc",
    template = "~/.config/cp/template.cc",  -- path to template file
    commands = { ... },
  },
}

On new problem file creation (when the file does not yet exist), read the template file and write it as the initial buffer content, performing token substitution for {problem}, {contest}, {platform}, {date}.

This is additive — the existing setup_code hook continues to work for users who need programmatic setup. The template file path is the simple, common case.

Alternatives considered

Keeping the setup_code hook as the only mechanism. This works but the onboarding friction is higher than a simple file path, especially for new users following the README.

## Problem Every competitive programmer uses a personal template (standard library includes, macros, typed aliases, I/O optimization). cp.nvim's `setup_code` hook lets users insert template content programmatically, but it requires writing Lua code — a higher bar than pointing to a file. Tools like cf-tool and competitest.nvim support a simple `template_path` string per language. ## Proposed solution Add a `template` key per language in the language config: ```lua languages = { cpp = { extension = "cc", template = "~/.config/cp/template.cc", -- path to template file commands = { ... }, }, } ``` On new problem file creation (when the file does not yet exist), read the template file and write it as the initial buffer content, performing token substitution for `{problem}`, `{contest}`, `{platform}`, `{date}`. This is additive — the existing `setup_code` hook continues to work for users who need programmatic setup. The template file path is the simple, common case. ## Alternatives considered Keeping the `setup_code` hook as the only mechanism. This works but the onboarding friction is higher than a simple file path, especially for new users following the README.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
barrettruth/cp.nvim#259
No description provided.