A minimalist Neovim plugin to automatically insert file templates based on file extensions. Great for competitive programming, boilerplate setup, or project scaffolding.
- Detects filetype via extension
- Loads templates from a configurable directory
- Prompts to select if multiple templates match
- Replaces
cursormarker with live cursor - Zero dependencies, pure Lua
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,
}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.
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!
~/.config/nvim/lua/templates/
βββ ai.py
βββ cp.cpp
βββ game.cpp
βββ operation.fish
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.
MIT