GitHubGet verd

Snippets and Templates

Two different things live in ~/.config/verd/snippets/ (change it with snippets_dir).

What Used
Template the starting text of a new solution, one per language automatically, when you press e the first time
Snippet a reusable piece of code (bfs, dijkstra, modpow) only when you ask

Templates#

templates/<lang>.<ext> is a Go text/template. Variables: {{.Problem.ID}}, {{.Problem.Name}}, {{.Problem.URL}}, {{.Handle}}, {{.Contest}}, {{.Index}}, {{.Date}}, {{.Time}}, {{.DateTime}}. {{cursor}} marks where the editor cursor starts.

// {{.Problem.ID}} {{.Problem.Name}}
// {{.Problem.URL}}
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    {{cursor}}
}

The default Templates (verd init --force refreshes yours) are tourist-style. C++ has debug(...) (a no-op 42 off LOCAL), ll, ull, pii, vi, all(x), sz(x), pb, F/S, fors(i, n), cin >> v and cout << v for a whole vector, YES(b)/NO(b), fast IO and while (T--) solve(). C has ll, ull, fors, min/max, read_int, read_ll and YES. Python has input, debug, INF, MOD, inp(), ints(), YES() and a raised recursion limit. Delete what you do not use.

Edit one from Settings (5) > Snippets, or open the file yourself. gen.<lang>.<ext> and brute.<lang>.<ext> are the stress helpers' Templates. A language's template = "/path" in [lang.*] overrides all of this.

The snippet library#

verd ships 35 snippets for C++ and Python and 34 for C (C has no wgraphinput): input readers (vecinput, matinput, gridinput, graphinput, wgraphinput), fastio, prefix_sum, prefix_sum_2d, diff_array, modpow, modinv, extgcd, sieve, spf_factorize, miller_rabin, divisors, ncr_mod, matrix_pow, bfs, grid_bfs, dfs, dijkstra, topo_sort, floyd_warshall, dsu, fenwick, segment_tree, sparse_table, binary_search, lis, compress, prefix_function, z_function, string_hash, debug.

Use one

verd snippet --list                  # names and descriptions (C++)
verd snippet --lang python --list
verd snippet dijkstra                # print it
verd snippet --copy modpow           # to the clipboard

In Neovim, :r !verd snippet dijkstra inserts it at the cursor. A unique prefix is enough (verd snippet dijk).

Add and edit from the TUI

Settings (5) > Snippets has three rows besides the Template:

In the pickers tab changes language and esc closes. They start on the language shown by the Template row (←/→ there). The command palette (ctrl+k, type snippet) jumps to these rows, except while a Problem is on screen.

Add your own from the shell

verd snippet add --desc "double it" twice twice.cpp     # from a file
echo 'x = 1' | verd snippet add --lang python xone -    # from stdin
verd snippet add --desc "my helper" helper              # no source: a stub opens in your editor

In Neovim, :'<,'>w !verd snippet add mysnip - saves the selected lines.

Command Does
verd snippet edit <name> edit one (a built-in gets an editable copy first)
verd snippet rm <name> remove your file; a built-in of that name comes back
verd snippet open open the library folder in your editor
verd snippet path print the snippets directory

A snippet is a file library/<lang>/<name>.<ext>; the comment on its first line is its description. A file with a built-in's name replaces it. They are plain code, with no {{...}} variables.

For LuaSnip or VSCode

verd snippet --export --lang cpp > ~/.config/nvim/snippets/verd-cpp.json
require("luasnip.loaders.from_vscode").load_standalone({ path = "~/.config/nvim/snippets/verd-cpp.json", lang = "cpp" })

Re-export after you edit the library.

In C: graphs

bfs, dfs, dijkstra and topo_sort build on graphinput (edge arrays); paste that one first. Everything else is self-contained.

Next: Customize. Reference: Configuration.