仕事でGoやほんの少しRustを触る機会があって、近しいnimがだいぶ気になっていたので、環境設定してみました

まずはnimをinstallしていきます


$ curl https://nim-lang.org/choosenim/init.sh -sSf | sh

Switched to Nim 1.6.4
choosenim-init: ChooseNim installed in /Users/masahirookubo/.nimble/bin
choosenim-init: You must now ensure that the Nimble bin dir is in your PATH.
choosenim-init: Place the following line in the ~/.profile or ~/.bashrc file.
choosenim-init:     export PATH=/Users/masahirookubo/.nimble/bin:$PATH

※brew install nimでもinstallできましたが、nimlspをinstallするタイミングで下記エラー出たので、上記でinstallを行っています

Error: cannot open file: /opt/homebrew/Cellar/nim/1.6.4/nim/nimsuggest/nimsuggest.nim

installが完了した環境変数をzshやbashに設置

# .zshrc
export PATH=/Users/masahirookubo/.nimble/bin:$PATH

設置完了したら反映して適用されているかを確認

$source ~/.zshrc
$ which nim
/Users/masahirookubo/.nimble/bin/nim

nimが問題なく設置できているので、次はlspを追加します

$ nimble install nimlsp
Downloading https://github.com/PMunch/nimlsp using git
  Verifying dependencies for nimlsp@0.4.0
      Info: Dependency on jsonschema@>= 0.2.1 already satisfied
  Verifying dependencies for jsonschema@0.2.1
      Info: Dependency on ast_pattern_matching@any version already satisfied
  Verifying dependencies for ast_pattern_matching@1.0.0
 Installing nimlsp@0.4.0
   Building nimlsp/nimlsp using c backend
/private/var/folders/bb/n3dq0s2963v_4c8dw8ygjlgm0000gn/T/nimble_45528/githubcom_PMunchnimlsp/src/nimlsppkg/baseprotocol.nim(26, 29) Warning: Deprecated since 1.5; TaintedString is deprecated [Deprecated]
   Success: nimlsp installed successfully.

lspが追加できたらcocの設定を行います

"nim": {
  "command": "nimlsp",
  "filetypes": ["nim"],
  "trace.server": "verbose"
}

lspの設定を行ってもnimファイルを認識しないことがあるので、私はこちらをvimrcに追加して強制的に認識させました

autocmd BufNewFile,BufRead *.nim, set filetype=nim

lsp入れ終わったので、一旦確認

型定義を表示できたので、一応これで開発はできそうです!

ガッツリ開発もしてみたいので、シンタックスも入れてみます

[[plugins]]
repo = 'baabelfish/nvim-nim'
on_ft = ['nim']

入れ終わるとこんな感じでシンタックス適用できて、かなりみやすくなりました!

参考記事

VimでのNim開発環境構築

NeovimでNimを書く環境を整える