Templates for all kinds of things. Read a file into your editor at the cursor
and jump to the <++> locations.
A therealtruex.com project.
Here is one such template:
(defpackage :<++>-system (:use :cl :asdf))
(in-package :<++>-system)
(defsystem <++>
:name "<++>"
:author "<++> <<++>@<++>.<++>>"
:version "<++>"
:maintainer "<++> <<++>@<++>.<++>>"
:license "GNU GPLv3.0"
:description "<++>"
;; put the most general files first to minimize the "depends on" use
;; and in that case you'll need :serial t
:serial <++>
:components ((:file "packages")
(:file "<++>" :depends-on ("<++>")))
:weakly-depends-on (<++>)
:depends-on (<++>))
One directory per language: c, cl (Common Lisp), sh (POSIX shell),
sed, awk, make, vim, html. A few loose templates sit at the root
(openrc.init, git-config-branch, uad.json).
Two kinds of file live here:
- Templates contain
<++>. Read them in and fill the gaps. - Cheat sheets contain no
<++>(for examplesed/TLDR,vim/use-g-v, most ofsh/). They are notes to read or:readin whole. The snippet converter skips them.
- The first line of a template is a one-line summary in the language's
comment syntax (
#,;;,//or<!-- -->). Tools read it as the description. A#!line may come before it. <++>marks a spot to fill.<+name+>does the same and names the spot, for example<+remote+>. The snippet converter turns the name into the placeholder text. Use the plain form unless a name helps.
bin/tmpl lists and prints templates. Put it on your PATH or call it by
path.
tmpl -l # list every file with its summary
tmpl -f # pick one with fzf and print it
tmpl sh for-find # print sh/for-find
tmpl sh/trap/cleanup-temp # the same, as one pathIn Vim, :r !tmpl sh for-find reads a template in at the cursor.
INDEX.md is the same list as a table. make index regenerates it.
:read /path/to/tmpl/thingAdd a shortcut on your leader key that jumps to the next placeholder, deletes
it, and leaves you in insert mode. The pattern matches both <++> and
<+name+>.
Vimscript:
map <leader><Space> /<+.\{-}+><CR>dt>a<BS>Lua:
map("n", "<leader><Space>", "/<+.\\{-}+><CR>dt>a<BS>", { desc = "Jump to next template placeholder" })convert_to_luasnip.py turns every template into a VSCode-format snippet.
Each language becomes one JSON file, and a package.json lists them for the
LuaSnip loader.
python3 convert_to_luasnip.py --dry-run # list what would be written
python3 convert_to_luasnip.py # write to ~/.config/nvim/snippets
python3 convert_to_luasnip.py --output some/dir # write elsewhereLoad the output in your Neovim config:
require("luasnip.loaders.from_vscode").lazy_load({
paths = { vim.fn.stdpath("config") .. "/snippets" }
})The snippet prefix is the path with dashes: c/main.c is c-main,
sh/trap/cleanup-temp is sh-trap-cleanup-temp. The description is the
template's summary comment. Type the prefix, press Tab, and Tab again to move
between the placeholders.
python3 -m pip install pytest hypothesis
make checkmake check parses the shell templates with sh -n and shellcheck,
compiles the C templates, reads the Lisp templates with sbcl when it is
installed, runs the Python tests, and confirms INDEX.md is current. The
GitHub Actions workflow runs the same target.
Many of the shell tricks come from https://www.etalabs.net/sh_tricks.html,
especially sh/for-find, a nightmare fixed-point solution.
