LoginSignup
0
0

Rust 用の Vim 環境を整える

Last updated at Posted at 2024-05-26

はじめに

自分用のメモ。

dotfiles

環境設定

rust.vim の導入

Rust の公式プラグイン。

dein.vim をプラグインマネージャーに使用しているので、TOML に設定してインストール。

.dein.toml
[[plugins]]
repo = "rust-lang/rust.vim"

保存時の rustfmt の適用

保存時に rustfmt フォーマッタを適用したい。
コンフィグに追加する。

~/.vim/.dein.toml
[[plugins]]
repo = "rust-lang/rust.vim"
hook_add = '''
let g:rustfmt_autosave = 1
'''

output.gif

rust-analyzer を適用する

もともと vim-lsp を使用していたけど、rust-analyzer のドキュメントには coc.nvim が例に書かれてたので、この際に Coc を入れて試してみることにする。
(てか coc が Vim で使えたの知らなかった。勝手に Neovim 専用だと勘違いしてた…

coc 自体のインストール

~/.vim/.dein.toml
[[plugins]]
repo = 'neoclide/coc.nvim'
branch = 'release'

rust-analyzer の coc セットアップ

:CocConfig コマンドで coc-settings.json ファイルを開いて編集
dotfiles で管理することにした

~/vimfiles/coc-settings.json
{
  "launguageserver": {
    "rust": {
      "command": "rust-analyzer",
      "filetypes": ["rust"],
      "rootPatterns": ["Cargo.toml"]
    }
  }
}

ここまで設定するだけで、もう「コード書けるぜ」までは行ける。
rust-analyzer 様様

image.png

トラブルシュート

build/index.js not found, please install dependencies and compile coc.nvim by: npm ci

coc.nvim を最初にインストールするとこの問題にぶつかった。

こちらのトラブルシュートで対応。
https://qiita.com/Taichi-yzrh/items/5868e618c82e328c89f6

:call coc#util#install()

Rust 操作メモ

rustfmt を任意で起動する

:RustFmt
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0