Skip to content

Rational-Idiot/template.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

template.nvim

A minimalist Neovim plugin to automatically insert file templates based on file extensions. Great for competitive programming, boilerplate setup, or project scaffolding.

✨ Features

  • Detects filetype via extension
  • Loads templates from a configurable directory
  • Prompts to select if multiple templates match
  • Replaces cursor marker with live cursor
  • Zero dependencies, pure Lua

πŸ“¦ Installation

Using lazy.nvim:

{
  "Rational-Idiot/template.nvim",
  lazy = false,
  config = function()
    --This is the default configuration, Change it to your templates directory
    require("template").setup({
      template_directory = vim.fn.stdpath("config") .. "/templates"
    })
    --Call :Template for the plugin
    --Uncomment the following to set the keymap
    -- vim.keymap.set("n", "<leader>ct", "<cmd>Template<CR>", { desc = "Insert file template" })
  end,
}

πŸ—‚οΈ Template Format

Place template files inside your configured directory, named like:

cp.cpp ai.py utility.sh

Have a line that says just "__cursor__" {it can also be commented} to mark the positio where you want to be placed after the template is inserted

Example:

# include <iostream>

using namespace std;

int main() {
    __cursor__
return 0;
}

The line containing cursor will be trimmed to just its indentation, and the cursor will be moved there in insert mode.

πŸš€ Usage

Open a new file with a any extension that you have a template for

Press <leader>ct (or run :Template)

Select a matching template (if multiple)

Done!

πŸ“ Example Template Directory

~/.config/nvim/lua/templates/
β”œβ”€β”€ ai.py
β”œβ”€β”€ cp.cpp
β”œβ”€β”€ game.cpp
└── operation.fish

πŸ’‘ Tips

Supports multiple templates per extension β€” you'll get a picker.
Use telescope and telescope-ui-select for a better experience

Use it with snippets for even more power.

πŸ“œ License

MIT

About

A nvim plugin that dynamically detetcts the file type and applies a template

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages