6 releases
| 0.1.5 | May 14, 2025 |
|---|---|
| 0.1.4 | Mar 6, 2025 |
| 0.1.3 | Feb 21, 2025 |
| 0.1.0 | Jan 18, 2025 |
#268 in Cargo plugins
651 downloads per month
1.5MB
1.5K
SLoC
๐ 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
๐ Table of Contents
๐ฅ Installation
Using lazy.nvim
{
"nwiizo/cargo.nvim",
build = "cargo build --release",
config = function()
require("cargo").setup({
float_window = true,
window_width = 0.8,
window_height = 0.8,
border = "rounded",
auto_close = true,
close_timeout = 5000,
})
end,
ft = { "rust" },
cmd = {
"CargoBench",
"CargoBuild",
"CargoClean",
"CargoDoc",
"CargoNew",
"CargoRun",
"CargoRunTerm",
"CargoTest",
"CargoUpdate",
"CargoCheck",
"CargoClippy",
"CargoAdd",
"CargoRemove",
"CargoFmt",
"CargoFix"
}
}
Using packer.nvim
use {
"nwiizo/cargo.nvim",
run = "cargo build --release",
config = function()
require("cargo").setup({
float_window = true,
window_width = 0.8,
window_height = 0.8,
border = "rounded",
auto_close = true,
close_timeout = 5000,
})
end,
}
๐ Requirements
- ๐ป Neovim >= 0.9.0
- ๐ฆ Rust and Cargo installed on your system
- ๐ Additional dependencies:
- Ubuntu/Debian:
libluajit-5.1-dev(Install withsudo apt install libluajit-5.1-dev) - macOS:
luajit(Install withbrew install luajit) - For other Linux distributions, you may need to install an equivalent LuaJIT development package
- Ubuntu/Debian:
If you encounter build errors mentioning lluajit-5.1 during installation, you likely 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("cargo").setup({
-- Window settings
float_window = true, -- Use floating window
window_width = 0.8, -- Window width (80% of editor width)
window_height = 0.8, -- Window height (80% of editor height)
border = "rounded", -- Border style ("none", "single", "double", "rounded")
wrap_output = true, -- Enable text wrapping in output window
show_line_numbers = true, -- Show line numbers in output window
show_cursor_line = true, -- Highlight current line in output window
-- Auto-close settings
auto_close = true, -- Auto close window on success
close_timeout = 5000, -- Close window after 5000ms
-- Timeout settings
run_timeout = 300, -- Timeout for cargo run in seconds
interactive_timeout = 30, -- Inactivity timeout for interactive mode
-- Advanced behavior options
force_interactive_run = true, -- Always treat cargo run as interactive mode
max_inactivity_warnings = 3, -- Maximum number of inactivity warnings before termination
detect_proconio = true, -- Enable detection of proconio usage
force_smart_detection = true, -- Always use smart detection for interactive programs
-- Key mappings (customizable)
keymaps = {
close = "q",
scroll_up = "<C-u>",
scroll_down = "<C-d>",
scroll_top = "gg",
scroll_bottom = "G",
interrupt = "<C-c>",
toggle_wrap = "w",
copy_output = "y",
clear_output = "c",
},
})
โจ๏ธ Key Mappings
In the floating window:
qor<Esc>- Close the window<C-c>- Cancel the running command<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
For interactive programs that require user input:
- An input field appears at the bottom of the window when needed
- Enter your input and press Enter to send it to the program
- The plugin automatically detects when a program is waiting for input
- The window automatically closes after a period of inactivity (configurable)
- Interactive mode timeout prevents hanging processes and memory leaks
๐ 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
Dependencies
~4โ8MB
~145K SLoC