Better workflow , testing and debugging capability on your Next Rust Projects
NOTE: Only MacOS Keymaps Are Well Documented on this README.md , I have remove all examples for windows/linux.
NOTE: At the moment , only MacOS have been tested and perfected for the workflow. You can Fork and Submit Pull Request If you wanted your Contribution to be added on Main Branch.
Installation on Macos and Linux
git clone https://github.com/codeitlikemiley/nvim
mv nvim ~/.config
cd nvim ~/.config/nvim
chmod +x ./install.sh
Please Check
./install.sh
before running it , especially if your on linux , your package manager might not be supported by the script
Requirements
Must Have Installed, check the link on how to install it
Warning: if you have existing neovim set up check this out
Note: if you forget keybindings just press SHIFT + SPACE
Any Commands that extends Cargo e.g.
cargo-watch
,cargo-leptos
ordioxus-cli
can be forced to be used instead ofcargo run
orcargo test
commands using aMakefile
Example Makefile for Running Cargo Leptos
# Makefile for a Rust project using cargo-leptos and cargo-nextest
# Default target
.PHONY: all
all: build
# Build target
.PHONY: build
build:
cargo leptos build
.PHONY: run
run:
cargo leptos watch
# Test target
.PHONY: test
test:
cargo nextest run
# Clean up
.PHONY: clean
clean:
cargo clean
The DAP Configuration can be added on Root Folder of your project with a name
.dap_config
, you can place any.lua
file here but it is important to remember theNaming Convention
if you wanna add configuration for rust then name the filerust.lua
If you have created
.dap_config
folder withrust.lua
inside it would load that dap configuration
Example Dap Configuration for Rust
local function get_configurations()
return {
{
type = 'codelldb',
request = 'launch',
name = "Debug executable 'server'",
cargo = {
args = {
"build",
"--bin=server",
"--package=server"
},
filter = {
name = "server",
kind = "bin"
}
},
args = {},
cwd = '${workspaceFolder}',
program = function()
return vim.fn.getcwd() .. '/target/debug/server'
end,
},
-- Add other configurations here...
}
end
return get_configurations
Ultimate Productivity Keybindings
SHIFT+SPACE === List and Search All Keymaps
Note: For Mac CMD for Windows/Linux replace it with ALT for different keymaps it is listed below
F1 === RustRunnables
F3 === RustDebuggables
F4 === Rust Parent Module
F5 === Reload Workspace
-- Mac Only
CMD + R === Smart Cargo Run and Test
CMD + D === Debug Test Under Cursor (mac)
CMD + K === Debug Continue (mac)
CMD + backtick
=== Toggle Debugger UI
CMD + J === Step Over
CMD + L === Step Into
CMD + H === Step Out
OPT + S === Continue
F8 === Dap Terminate
CMD + I === Rust Toggle Inlay Hints
-- Mac Only
CMD + B === Toggle Breakpoint (mac)
F2 === Rename
CMD + S === Save
CMD + V === Paste
CMD + Z === Undo
CMD + . === Code Actions
CMD + M === Expand Rust Macro
CMD + slash === Comment Selected Lines on Visual / Normal Mode
slash + slash === Comment Line
Note: this is for MacOS users only
OPT + J,K === Move Line Up and Down
Note: You need to Rebind CMD + Q to use Smart Quit (optional) , defaults to Quit
Neovide
CMD + Q === Quit All
CMD + N === New Tab
CMD + Y === Rebuild Proc Macro
CMD + [1-9] === Switch Tab [1-9]
CMD + F1 === Toggle Sidebar
CMD + F2 === Neotest Summary
CMD + F3 === Diff View File
CMD + F4 === Diff Close View
CMD + F5 === Toggle Test Summary
CMD + F6 === Reload VimRC
OPT + D === Diff View File History
CMD + F === Find Everything on Workspace
CMD + G === Open Lazy Git
OPT + D === Diff File History
CMD + O === Go to Symbols on Current Open File
CMD + T === Go to Workspace Symbols
CMD + P === Open Recent Files
CMD + E === Open Copilot Chat Actions
Some Built in Keybindings by Lazy Nvim
leader + uf === Toggle Formatting
Key | Description | Mode |
---|---|---|
gd |
Goto Definition | n |
gr |
References | n |
gD |
Goto Declaration | n |
gI |
Goto Implementation | n |
gy |
Goto T[y]pe Definition | n |
K |
Hover | n |
]d |
Next Diagnostic | n |
[d |
Prev Diagnostic | n |
]e |
Next Error | n |
[e |
Prev Error | n |
]w |
Next Warning | n |
[w |
Prev Warning | n |
<leader>cf |
Format Document | n |
<leader>ca |
Code Action | n, v |
<leader>cA |
Source Action | n |
<leader>cr |
Rename | n |
Note: usage is press eg. f / F then the character to search eg: a then press any highligted 1 char to jump into
f === Jump to Char Forward
F === Jump to Char Backward
Note: you can use n to search forward and N to search backward
/ === Search for Characters
gw === Search Word under cursor
Checkout Built-in Snippets with Rust
Click here to view the snippets- allow
- assert
- assert_eq
- bench
- cfg
- cfg_attr
- cfg!
- column
- concat
- concat_idents
- const
- deny
- debug_assert
- debug_assert_eq
- derive
- env
- extern-crate
- extern-fn
- extern-mod
- else
- enum
- Err
- file
- format
- format_args
- fn
- for
- include
- include_bytes
- include_str
- if-let
- if
- impl-trait
- impl
- inline-fn
- line
- loop
- let
- macro_use
- module_path
- main
- match
- mod
- mod-block
- macro_rules
- no_std
- no_core
- option_env
- Ok
- panic
- println
- pfn
- repr
- stringify
- static
- Some
- struct-tuple
- struct-unit
- struct
- thread_local
- try
- test
- trait
- type
- unimplemented
- unreachable
- vec
- write
- writeln
- while-let
- while
How to add custom snippets?
- Create a file in
~/.config/nvim/snippets/rust.snippets
mkdir -pv ~/.config/nvim/snippets && touch ~/.config/nvim/snippets/rust.snippets
- Edit
~/.config/nvim/lua/plugins/snip.lua
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").load({
include = { "rust" },
-- Uncomment paths
paths = {
"~/.config/nvim/snippets"
},
})
end,
},
- Add your custom snippets in
~/.config/nvim/snippets/rust.snippets
Note: Format should be the same as vscode snippets eg. built-in-rust-snippets
As a reference on the structure of these snippet libraries, see friendly-snippets.
We support a small extension: snippets can contain LuaSnip-specific options in the luasnip-table:
"example1": {
"prefix": "options",
"body": [
"whoa! :O"
],
"luasnip": {
"priority": 2000,
"autotrigger": true,
"wordTrig": false
}
}
Files with the extension jsonc will be parsed as jsonc, json with comments, while *.json are parsed with a regular json parser, where comments are disallowed. (the json-parser is a bit faster, so don't default to jsonc if it's not necessary).
Example:
~/.config/nvim/my_snippets/package.json
:
{
"name": "example-snippets",
"contributes": {
"snippets": [
{
"language": [
"all"
],
"path": "./snippets/all.json"
},
{
"language": [
"lua"
],
"path": "./lua.json"
}
]
}
}
~/.config/nvim/my_snippets/snippets/all.json:
{
"snip1": {
"prefix": "all1",
"body": [
"expands? jumps? $1 $2 !"
]
},
"snip2": {
"prefix": "all2",
"body": [
"multi $1",
"line $2",
"snippet$0"
]
}
}
~/.config/nvim/my_snippets/lua.json
:
{
"snip1": {
"prefix": "lua",
"body": [
"lualualua"
]
}
}
This collection can be loaded with any of
-- don't pass any arguments, luasnip will find the collection because it is (probably) in rtp.
require("luasnip.loaders.from_vscode").lazy_load()
-- specify the full path...
uarequire("luasnip.loaders.from_vscode").lazy_load({paths = "~/.config/nvim/my_snippets"})
-- or relative to the directory of $MYVIMRC
require("luasnip.loaders.from_vscode").load({paths = "./my_snippets"})
Standalone