feature: add vim-rust
authorAJ ONeal <aj@therootcompany.com>
Sun, 15 Aug 2021 05:07:49 +0000 (05:07 +0000)
committerAJ ONeal <aj@therootcompany.com>
Sun, 15 Aug 2021 05:08:30 +0000 (05:08 +0000)
rust.vim [new symlink]
vim-rust/README.md [new file with mode: 0644]
vim-rust/install.ps1 [new file with mode: 0644]
vim-rust/install.sh [new file with mode: 0644]
vim-rust/rust.vim [new file with mode: 0644]

diff --git a/rust.vim b/rust.vim
new file mode 120000 (symlink)
index 0000000..ec53515
--- /dev/null
+++ b/rust.vim
@@ -0,0 +1 @@
+vim-rust
\ No newline at end of file
diff --git a/vim-rust/README.md b/vim-rust/README.md
new file mode 100644 (file)
index 0000000..56e8694
--- /dev/null
@@ -0,0 +1,50 @@
+---
+title: vim-rust
+homepage: https://github.com/rust-lang/rust.vim
+tagline: |
+  vim-rust (rust.vim) adds Rust language support for Vim.
+---
+
+To update (replacing the current version) run `webi vim-rust`.
+
+## Cheat Sheet
+
+> `vim-rust` provides integration with `cargo check`, `rustfmt`, and other rust
+> tooling.
+
+You'll also need to install [`ALE`](https://webinstall.dev/vim-ale) (part of
+[`vim-essentials`](https://webinstall.dev/vim-essentials)) or
+[`syntastic`](https://webinstall.dev/vim-syntastic) first.
+
+### How to install and configure by hand
+
+1. Remove the previous version of rust.vim, if any:
+   ```bash
+   rm -rf ~/.vim/pack/plugins/start/rust.vim
+   ```
+2. Install `rust.vim` as a Vim8 package with `git`:
+   ```bash
+   mkdir -p ~/.vim/pack/plugins/start/
+   git clone --depth=1 \
+       https://github.com/rust-lang/rust.vim \
+       ~/.vim/pack/plugins/start/rust.vim
+   ```
+3. Create `~/.vim/plugins/rust.vim`, as follows:
+
+   ```vim
+   " Reasonable defaults for rust.vim
+
+   " run rustfmt on save
+   let g:rustfmt_autosave = 1
+
+   " run cargo check et al
+   let g:ale_rust_cargo_use_check = 1
+   let g:ale_rust_cargo_check_tests = 1
+   let g:ale_rust_cargo_check_examples = 1
+   ```
+
+4. Edit `~/.vimrc` to include the config:
+   ```vim
+   " Rust: reasonable defaults for rust.vim
+   source ~/.vim/plugins/rust.vim
+   ```
diff --git a/vim-rust/install.ps1 b/vim-rust/install.ps1
new file mode 100644 (file)
index 0000000..0ef2145
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/env pwsh
+
+New-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start" -ItemType Directory -Force | out-null
+
+Remove-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start\rust.vim" -Recurse -ErrorAction Ignore
+& git clone --depth=1 https://github.com/rust-lang/rust.vim "$Env:USERPROFILE\.vim\pack\plugins\start\rust.vim"
diff --git a/vim-rust/install.sh b/vim-rust/install.sh
new file mode 100644 (file)
index 0000000..f2389e1
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+function __init_vim_rust() {
+    set -e
+    set -u
+
+    mkdir -p "$HOME/.vim/pack/plugins/start"
+    rm -rf "$HOME/.vim/pack/plugins/start/rust.vim"
+    git clone --depth=1 https://github.com/rust-lang/rust.vim "$HOME/.vim/pack/plugins/start/rust.vim"
+
+    if [ -f "$HOME/.vimrc" ]; then
+        set +e
+        if ! grep 'source.*rust.vim' -r ~/.vimrc; then
+            mkdir -p ~/.vim/plugins
+            printf '\n" Rust: reasonable defaults from webinstall.dev/vim-rust\n' >> ~/.vimrc
+            printf 'source ~/.vim/plugins/rust.vim\n' >> ~/.vimrc
+        fi
+        set -e
+    fi
+
+    if ! [ -f "$HOME/.vim/plugins/rust.vim" ]; then
+        mkdir -p ~/.vim/plugins
+        WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
+        curl -fsS -o ~/.vim/plugins/rust.vim "$WEBI_HOST/packages/vim-rust/rust.vim"
+    fi
+}
+
+__init_vim_rust
diff --git a/vim-rust/rust.vim b/vim-rust/rust.vim
new file mode 100644 (file)
index 0000000..7b4aec2
--- /dev/null
@@ -0,0 +1,12 @@
+""""""""""""""""""""""""""""""""
+"    Rust-specific defaults    "
+" from webinstall.dev/vim-rust "
+""""""""""""""""""""""""""""""""
+
+" run rustfmt on save
+let g:rustfmt_autosave = 1
+
+" run cargo check for linting
+let g:ale_rust_cargo_use_check = 1
+let g:ale_rust_cargo_check_tests = 1
+let g:ale_rust_cargo_check_examples = 1