1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-01 04:40:06 +08:00
SpaceVim/docs/layers/lang/rust.md

99 lines
3.3 KiB
Markdown
Raw Normal View History

---
title: "SpaceVim lang#rust layer"
2021-06-21 20:39:29 +08:00
description: "This layer is for Rust development, provides autocompletion, syntax checking, and code formatting for Rust files."
---
# [Available Layers](../../) >> lang#rust
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Features](#features)
- [Install](#install)
- [Layer](#layer)
2020-03-04 20:13:16 +08:00
- [language tools](#language-tools)
2019-03-18 00:12:11 +08:00
- [Layer options](#layer-options)
- [Key bindings](#key-bindings)
2020-07-31 22:25:33 +08:00
- [Inferior REPL process](#inferior-repl-process)
- [Running current script](#running-current-script)
<!-- vim-markdown-toc -->
## Description
2019-02-03 20:51:01 +08:00
This layer is for Rust development.
## Features
- Code completion
- Syntax checking
- Syntax highlighting and indent
- Documentation lookup
- Jump to the definition.
- Find references
2020-02-06 13:31:07 +08:00
- Rename symbol
- Cargo integration
- Code formatting
2021-06-21 20:39:29 +08:00
SpaceVim also provides code runner and Language Server Protocol support for Rust. To enable LSP, you need to load the `lsp` layer for Rust.
## Install
### Layer
2021-06-21 20:39:29 +08:00
To use this configuration layer, update your custom configuration file with:
```toml
[[layers]]
name = "lang#rust"
```
2020-03-04 20:13:16 +08:00
### language tools
- [evcxr](https://github.com/google/evcxr): A REPL (Read-Eval-Print loop) for Rust.
2019-03-18 00:12:11 +08:00
## Layer options
2020-07-31 22:25:33 +08:00
- `recommended_style`: `true`/`false` (Enable/Disable) recommended code style for rust. This option is disabled by default.
2021-06-21 20:39:29 +08:00
- `format_on_save`: `true`/`false` (Enable/Disable) format current buffer after save. This option is disabled by default.
2020-07-31 22:25:33 +08:00
- `racer_cmd`: The path of `racer` binary. This option is `racer` by default.
- `rustfmt_cmd`: The path of `rustfmt` binary. This option is `rustfmt` by default.
2019-03-18 00:12:11 +08:00
## Key bindings
2020-02-06 13:31:07 +08:00
| Key bindings | Descriptions |
| --------------- | ---------------------------------- |
| `g d` | Jump to definition |
| `SPC l d` / `K` | Show doc of cursor symbol |
2020-07-31 22:25:33 +08:00
| `SPC l g` | Jump to definition |
| `SPC l v` | Jump to definition (vertical) |
2021-06-21 20:39:29 +08:00
| `SPC l e` | Rename symbol (needs `lsp` layer) |
| `SPC l u` | Show references (needs `lsp` layer)|
2020-02-06 13:31:07 +08:00
| `SPC l c b` | Run `cargo build` |
| `SPC l c c` | Run `cargo clean` |
| `SPC l c f` | Run `cargo fmt` |
| `SPC l c t` | Run `cargo test` |
| `SPC l c u` | Run `cargo update` |
| `SPC l c B` | Run `cargo bench` |
| `SPC l c D` | Run `cargo doc` |
| `SPC l c r` | Run `cargo run` |
| `SPC l c l` | Run `cargo clippy` |
2021-06-21 20:39:29 +08:00
**Note:** `SPC l g` and `SPC l v` will not be available if the `lsp` layer is not enabled.
2020-07-31 22:25:33 +08:00
### Inferior REPL process
Start a `evcxr` inferior REPL process with `SPC l s i`.
Send code to inferior process commands:
| Key Bindings | Descriptions |
| ------------ | ------------------------------------------------ |
| `SPC l s b` | send buffer and keep code buffer focused |
| `SPC l s l` | send line and keep code buffer focused |
| `SPC l s s` | send selection text and keep code buffer focused |
### Running current script
2021-06-21 20:39:29 +08:00
To run a rust file, you can press `SPC l r` to run the current file without losing focus, and the result will be shown in a runner buffer.