New Rust projects from inside Neovim: a binary, a library, a workspace (with the version and edition inherited from the workspace) or an egui app, each behind a few guarded prompts, plus optional entries for the snacks.nvim dashboard.
I use this in my own Rust setup, xynovim, and pulled it out as a standalone plugin.
cargo new makes a binary or a library, but not a workspace, and starting a project means leaving the editor to find a directory, check the name rules and cd. This asks for the name and the parent directory, applies cargo's name rules before anything is created, builds the workspace layout cargo has no command for, leaves nothing behind when a step fails, and opens the new project's source file. :EguiNew starts from the current eframe_template instead of a stale copy.
- Neovim 0.12+
- xyno-rust.nvim (a required dependency:
xyno_rust.rust_contextfinds the workspace for:RustNewMember,xyno_rust.fsutilis used for the nesting check). If it is missing,setup()prints one error line and defines nothing.setup()also checks the API version (require("xyno_rust").compatible(require("xyno_new").requires_rust_api), now1.1): a xyno-rust.nvim with another major or an older minor gives one error line naming the fix, and nothing starts. The CI workflow fetches the dependencies by tag (XYNO_RUST_REF), nevermain; pin your own plugin manager the same way (tag = "v0.2.0"or a commit) so a breaking major cannot arrive unannounced. cargoin$PATHgit(optional): used forgit init -b mainin a workspace and for:EguiNew, and to prefill the author prompts. Without it those steps are skipped with a note.- for
:EguiNew:curlandunzip(on Windowstarinstead ofunzip), network access to github.com for the first download (the ZIP is cached, with its ETag, and used when offline), andrustcfor the minimum-version warning - optional: snacks.nvim for the dashboard entries and for
egui_build_after_new
{
"xynorash/xyno-new.nvim",
dependencies = { "xynorash/xyno-rust.nvim" },
cmd = { "RustNewBin", "RustNewLib", "RustNewWorkspace", "RustNewMember", "EguiNew" },
opts = {},
keys = {
{ "<leader>rnb", "<cmd>RustNewBin<cr>", desc = "New Rust binary" },
{ "<leader>rni", "<cmd>RustNewLib<cr>", desc = "New Rust library" },
{ "<leader>rnw", "<cmd>RustNewWorkspace<cr>", desc = "New Rust workspace" },
{ "<leader>rnm", "<cmd>RustNewMember<cr>", desc = "New member in this workspace" },
{ "<leader>rne", "<cmd>EguiNew<cr>", desc = "New egui project" },
},
}Because the commands are listed in cmd, lazy.nvim loads the plugin when you run one of them; setup() then defines them (the first run of a command through cmd is forwarded by lazy.nvim).
require("xyno_new").setup(opts); the defaults:
{
commands = true, -- :RustNewBin :RustNewLib :RustNewWorkspace :RustNewMember :EguiNew
keymaps = false, -- false | true | { bin = lhs, lib = lhs, ... } (global, normal mode)
projects_dir = nil, -- parent directory offered by the prompts; nil: ~/projects if it exists, else the cwd
egui_template = nil, -- { repo = "emilk/eframe_template", ref = <pinned commit>, base_url = "https://github.com", allow_insecure = false }
workspace = {}, -- template of :RustNewWorkspace, see the table below
egui_build_after_new = nil, -- true: run `cargo build` in a snacks terminal after :EguiNew
}| option | default | meaning |
|---|---|---|
commands |
true |
define the five commands |
keymaps |
false |
true or a table of the keys you want |
projects_dir |
~/projects if it exists, else the cwd |
parent directory the prompts offer |
egui_template.repo / ref / base_url / allow_insecure |
emilk/eframe_template / pinned commit / https://github.com / false |
where :EguiNew downloads the template from |
egui_build_after_new |
nil |
true: cargo build in a snacks terminal afterwards |
workspace.members_dir |
"crates" |
directory of the members; the manifest lists "<dir>/*" |
workspace.version |
"0.1.0" |
[workspace.package] version |
workspace.gitignore |
"/target\n" |
content of the workspace .gitignore (at most 4096 bytes) |
workspace.git |
true |
run git init in the new workspace |
workspace.git_branch |
"main" |
its initial branch |
The options are validated: an invalid egui_template or workspace is refused as a whole with one error line naming every problem (the defaults stay); a second setup() replaces the first one's workspace template.
Highlights: this plugin draws no window of its own (the prompts are vim.ui.input / vim.ui.select, the dashboard entries are snacks'), so it defines no XynoNew* groups; they follow your UI plugin and colorscheme.
projects_dir, egui_template and egui_build_after_new are stored in vim.g.xyno_new_projects_dir, vim.g.xyno_new_egui_template and vim.g.xyno_new_egui_build_after_new, which the modules read; you can set those variables directly instead. egui_template.base_url must be an https:// URL. http:// and file:// are refused unless you set egui_template.allow_insecure = true (a mirror on a trusted network, or a local copy for tests; the specs use it); a URL with credentials (user@host) is refused. The refusal happens before any request.
The template is pinned. egui_template.ref defaults to a commit of emilk/eframe_template (xyno_new.egui.PINNED_REF, f108546, 2026-08-31, egui 0.36), not to main, so the project you get does not change under you and the personalisation was checked against that exact tree. The spec against the real template downloads that commit from GitHub and personalises it (it needs network and skips without). I did not build the generated project in this run (it would compile egui and its dependencies), so "it compiles" is not claimed. ref = "main" follows the template's newest state like before; the pin moves only when this plugin is updated (change PINNED_REF on purpose and re-run the template specs). :checkhealth xyno_new shows what is in use.
No global keymap is set by default. keymaps = true maps <leader>rnb, rni, rnw, rnm, rne (binary, library, workspace, member, egui). A table maps only the actions you list, to the keys you choose (false skips one).
A picker over the built-in kinds (binary, library, workspace, member, egui) and a pinned list you configure:
require("xyno_new").setup({ templates = { { name = "axum service", path = "~/templates/axum", description = "axum + tracing" }, { name = "cli", git = "https://github.com/me/cli-template", rev = "<40-hex commit>" }, } })
A template is copied; {{name}}, {{crate_name}} and {{title}} are replaced in text files and file names. A git template needs the exact 40-hex commit (a branch can move); it is cloned without hooks and checked out detached. Nothing is executed: a template with cargo-generate.toml hooks or any .rhai file is refused, and so is one with a symbolic link. This is deliberately not cargo-generate: its templates run Rhai scripts, so using one is running its author's code. Placeholders beyond the three above (prompts, conditionals) are not supported.
Package and workspace names follow cargo's rules before anything is created: ASCII letters, digits, - and _ (whatever your locale), not starting with a digit or -, no Rust keyword, no name cargo reserves (test, std, deps, ...), no Windows device name (nul, con, com1, ... are refused on every platform so the project can move to Windows), at most 64 characters. A workspace name also must not end with - and must leave room for its default first member (<name>-app / <name>-core is at most 64 characters), and the error says why.
:RustNewMember, the nesting check and the inheritance of version/edition read the workspace's Cargo.toml in every TOML spelling of the workspace table: [workspace] with members = [...], the dotted key workspace.members = [...] (also with spaces or quotes around the parts), an inline workspace = { members = [...] }, and workspace.package.version, package.version under [workspace] or an inline package = { ... }. Keys of other tables ([package], [[bin]], [other.workspace]) are not mistaken for the workspace's. Limits: it is a line-oriented reader, not a TOML parser: a members array built over several lines with a ] inside a string is read correctly, but multi-line strings that look like keys are not skipped.
| Command | What it does |
|---|---|
:RustNewBin [name] |
cargo new --bin --vcs git: asks for the name (taken from the argument when it is valid) and the parent directory, then switches to the project and opens src/main.rs. |
:RustNewLib [name] |
The same with --lib and src/lib.rs. A name with hyphens shows the crate identifier it will have in Rust code. |
:RustNewWorkspace [name] |
Asks for the workspace name, the parent directory, the kind of the first member (binary or library) and its name. Writes Cargo.toml ([workspace] with members = ["crates/*"], [workspace.package] with version and the edition your cargo uses for new projects, an empty [workspace.dependencies]), .gitignore, creates the first member with cargo new --vcs none crates/<member> so that its version and edition inherit from the workspace, and runs git init -b main (no commit). Asks first when the parent lies in another workspace's members or in a git work tree. |
:RustNewMember [name] |
Adds a binary or library crate to the workspace of the current buffer (or the cwd). It adds the path to an explicit members list, or relies on a glob. Refuses a name that clashes with an existing member (hyphen or underscore) or a directory that exists. |
:EguiNew [name] |
Downloads the pinned eframe_template commit as a ZIP (never a copy kept in the plugin), asks for the crate name, author name, author e-mail (both may be empty) and the parent directory, and personalises it the way the template's README and fill_template.sh describe: crate name, authors, window and page title, the web build file names in assets/sw.js. Nothing from the template is executed. The template's rust-toolchain file is never copied; its rust-version stays as the minimum, and a warning says when your rustc is older. |
A prompt that is cancelled ends the command silently, and a failed step removes what that run created. Only one project is created at a time.
require("xyno_new").dashboard_keys(keys) inserts four entries into a list of snacks.nvim dashboard keys, in place, and returns it: b New Rust Binary, i New Rust Library, w New Rust Workspace, e New egui Project. The Rust three go right before the egui entry, which goes right before "Quit" (or last when there is none). Calling it twice adds nothing twice; an existing key e is respected. The key letters are free in LazyVim's stock dashboard (f n p g r c s x l q are taken). Nothing happens unless you call it:
{
"folke/snacks.nvim",
opts = function(_, opts)
opts.dashboard = opts.dashboard or {}
opts.dashboard.preset = opts.dashboard.preset or {}
opts.dashboard.preset.keys = require("xyno_new").dashboard_keys(opts.dashboard.preset.keys or {})
end,
}The entries run :RustNewBin and the others, so the plugin has to be loaded when you press them: list the commands in cmd as above, or load it with lazy = false.
| Module | Public functions |
|---|---|
xyno_new |
setup(opts), dashboard_keys(keys?), defaults, default_keymaps |
xyno_new.rust |
setup(), new_project(kind, name?), new_workspace(name?), new_member(name?), running(), the text functions name, lib_note, first_line, parse_edition, resolver, workspace_toml, inherit, workspace_info, add_member_path, layout, nesting_warning, and cargo_edition(), reset_edition(), create_project(p, cb), create_workspace(p, cb), create_member(p, cb) |
xyno_new.egui |
setup(), new(name?), create(p, cb), validate_name, cargo_name, check_author, format_author, edit_cargo_toml, edit_cargo_lock, readme, config(), default_parent(), expand_dir(s), parse_version, check_rust_version(dir, done?) and the other pure text functions |
xyno_new.dashboard |
keys(keys?), rust_entries, egui_entry |
:help xyno-new-api lists the main ones.
Every external command is an argv list run asynchronously (a small coroutine helper around vim.system), so the editor stays responsive and nothing goes through a shell. The text edits (name rules, the workspace manifest, inheriting version and edition, adding a member path, personalising the template) are pure functions. The edition is read once per session from a throwaway cargo new, never hard-coded; the resolver is 3 for edition 2024 and newer, else 2. A failed step restores or removes only what the run created.
- Linux: tested by the specs in this repository (
nvim -l tests/run.lua) with a real cargo; the egui flow runs against a local fake template (file:// and a small http server inside the test Neovim), plus one test against the real template that skips without network. - Windows: the Windows branches of the original code are kept (
tarinstead ofunzip), but I have no evidence for them. In xynovim's CI the specs for this code were skipped whole on Windows. - macOS: the specs carry the
linux,macosheader and ran there in xynovim's CI, whose macOS runs were not stable overall (one fully green run, others flaky or failed elsewhere), so I do not claim it works. - The dashboard entries are a snacks.nvim feature; the rendering of the dashboard in a terminal (tmux) was checked by the original specs in xynovim's config, not by the specs here.
These modules come from xynovim, my Neovim configuration for Rust (config.rust_new and config.egui_new, and the two dashboard plugin specs). The code is the same apart from the namespace (config.* became xyno_new.* and xyno_rust.*), setup() taking options, the vim.g.xynovim_* variables now being vim.g.xyno_new_*, the dashboard code being the opt-in function dashboard_keys() instead of lazy.nvim plugin specs, the notification ids, cache directory and the user agent carrying this plugin's name, and the "next steps" hint naming :RustTargets instead of a key.
nvim -l tests/run.lua # specs, each file in its own headless nvim XYNO_RUST=/path/to/xyno-rust.nvim nvim -l tests/run.lua # where xyno-rust.nvim is (default: a sibling directory) XYNO_LAZY=/path/to/lazy.nvim XYNO_RUST=/path/to/xyno-rust.nvim nvim --headless -u tests/e2e/init.lua -c "luafile tests/e2e/smoke.lua"
Specs that need cargo, curl, unzip or python3 skip with a message when it is missing.
MIT, Copyright (c) 2026 Xynorash.