๐ cargo.nvim
๐ฆ A Neovim plugin that provides seamless integration with Rust's Cargo commands. Execute Cargo commands directly from Neovim with a floating window interface.

โจ Features
- ๐ง Execute Cargo commands directly from Neovim
- ๐ช Real-time output in floating windows
- ๐จ Syntax highlighting for Cargo output
- โก Asynchronous command execution
- ๐ Auto-closing windows on command completion
- โจ๏ธ Easy keyboard shortcuts for window management
- ๐ Terminal mode for interactive applications
๐ฏ Scope
cargo.nvim is a faithful front-end to the cargo CLI inside Neovim: it runs Cargo
subcommands and shows their streamed output in a readable window, including
interactive programs (via terminal mode). It is intentionally a command runner and
report viewer, not a language-intelligence layer.
It complements, rather than replaces, the LSP-based Rust tooling you may already use:
- rust-analyzer / rustaceanvim โ inline diagnostics, jump-to-error, hover, macro expansion, code actions, runnables/testables.
- crates.nvim โ editing dependencies inside
Cargo.toml. - neotest โ structured test running and navigation.
If you run those, cargo.nvim is most useful for the Cargo subcommands they don't
surface (e.g. audit, outdated, tree, vendor, publish, doc, bench) and
for running interactive programs. Overlapping commands such as check, clippy,
test, and run remain available for backward compatibility, but the LSP/neotest
equivalents generally offer a richer experience.
๐ Table of Contents
- ๐ cargo.nvim
๐ฅ Installation
Using lazy.nvim
Using packer.nvim
use
๐ Requirements
- ๐ป Neovim >= 0.9.0
- ๐ฆ Rust and Cargo installed on your system
- ๐ LuaJIT development libraries (REQUIRED for building):
- Ubuntu/Debian:
sudo apt install libluajit-5.1-dev - macOS:
brew install luajit - Arch Linux:
sudo pacman -S luajit - Fedora:
sudo dnf install luajit-devel
- Ubuntu/Debian:
Important: You must install the LuaJIT development package BEFORE installing this plugin. The plugin includes a native Rust library that links against LuaJIT.
Troubleshooting
If you see "Cargo library not found" error after installation:
- Check if LuaJIT dev package is installed (see above)
- Rebuild the library manually:
- Verify the library was built:
# Should show libcargo_nvim.so (Linux) or libcargo_nvim.dylib (macOS)
If cargo build --release fails with "unable to find library -lluajit-5.1", you need to install the LuaJIT development package for your system.
๐ ๏ธ Available Commands
Core Commands
- ๐
:CargoBench- Run benchmarks - ๐๏ธ
:CargoBuild- Build the project - ๐งน
:CargoClean- Remove generated artifacts - ๐
:CargoDoc- Generate project documentation - โจ
:CargoNew- Create a new Cargo project - โถ๏ธ
:CargoRun- Run the project in a floating window - ๐
:CargoRunTerm- Run the project in terminal mode (better for interactive applications) - ๐งช
:CargoTest- Run tests - ๐
:CargoUpdate- Update dependencies
Additional Commands
- ๐
:CargoCheck- Check the project for errors - ๐
:CargoClippy- Run the Clippy linter - โ
:CargoAdd- Add dependency - โ
:CargoRemove- Remove dependency - ๐จ
:CargoFmt- Format code with rustfmt - ๐ง
:CargoFix- Auto-fix warnings - ๐ฆ
:CargoPublish- Publish package - ๐ฅ
:CargoInstall- Install binary - ๐ค
:CargoUninstall- Uninstall binary - ๐
:CargoSearch- Search packages - ๐ฒ
:CargoTree- Show dependency tree - ๐ฆ
:CargoVendor- Vendor dependencies - ๐ก๏ธ
:CargoAudit- Audit dependencies - ๐
:CargoOutdated- Check outdated dependencies - ๐ค
:CargoAutodd- Automatically manage dependencies
โ๏ธ Configuration
You can customize cargo.nvim by passing options to the setup function:
require.
Custom Commands
The commands table is extensible: add an entry to register a new :Cargo*
command from your configuration alone โ no rebuild required. Each entry may set
cmd (the actual Cargo subcommand, defaults to the key) and args (arguments
prepended before any you type):
require.
The key becomes the command name (testRelease โ :CargoTestRelease). When
nargs is omitted it defaults to "*", so extra arguments are still accepted.
โจ๏ธ Key Mappings
In the floating window:
qor<Esc>- Close the window<C-c>- Interrupt the running commandi- Send a line to the program's stdin<C-u>- Scroll up<C-d>- Scroll downgg- Scroll to topG- Scroll to bottomw- Toggle text wrappingy- Copy all output to clipboardc- Clear output
๐ Interactive Mode
Commands run asynchronously: output is streamed into the floating window as it is produced, and you stay in control of the editor while a command runs.
For programs that read from stdin:
- Press
iin the output window to be prompted for a line of input, which is sent to the running program's stdin. - Press
<C-c>to interrupt (terminate) the running command at any time.
For terminal-style programs that need a full TTY (e.g. proconio, TUIs), prefer
Terminal Mode below.
๐ Terminal Mode
For highly interactive applications (e.g., using proconio or TUI applications):
- Use
:CargoRunTermto run your application in a terminal emulator inside a floating window - Supports full terminal capabilities for interactive Rust applications
- Useful for:
- Competitive programming with libraries like proconio
- Text-based UI applications
- Programs requiring advanced terminal input/output
- Provides a better experience than the standard
:CargoRunfor interactive applications
Terminal Mode Key Mappings
qor<Esc>- Close the window (after program completion)<C-\><C-n>- Switch to normal mode (while running)<C-c>- Send interrupt signal<C-d>- Send EOF signal
๐ฅ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- ๐ด Fork the repository
- ๐ฟ Create a feature branch
- โ๏ธ Commit your changes
- ๐ Push to the branch
- ๐ซ Open a Pull Request
๐ License
MIT License - see the LICENSE file for details.
๐ Acknowledgements
This plugin is inspired by various Neovim plugins and the Rust community.
๐ Related Projects
- cargo-autodd - A tool for automatic dependency management