Skip to main content
こんにゃくの畑

Windows11でnvim-treesitterをセットアップ

Windows11でnvim-treesitterのパーサーをビルド、設定する方法。

コンパイラ準備

コンパイラはMinGW-W64を使用しました。
MinGW-W64にはいくつか導入方法があるようですが、今回はMinGW-W64-binariesのオンラインインストーラーを利用しました。
このオンラインインストーラーは、GitHubのREADMEにあるリンクからダウンロードできます。
(リンクは下記画像を参照)

インストーラーを実行するといくつかの選択項目があります。
(下の画像はバージョン選択時)

アーキテクチャやランタイムなどは下表のように設定しました。

項目
version 13.2.0
architecture 64bit
thread model win32
build version rev1
C runtime msvcrt
インストール先 C:/Users/{username}/

インストール完了後、環境変数PathにC:\Users\{username}\mingw64\binを追加して、
PowerShellでgccが通ることを確認しました。

lazy.nvimの設定

プラグインはlazy.nvimを使っています。
curlをデフォルトのインストール方法、gccをインストール時のコンパイラに設定するため、installの関数を作成します。
具体的には、nvim-treesitterの設定箇所は次のようにしました。

-- nvim-treesitterの設定
  {
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'nvim-treesitter/nvim-treesitter-textobjects',
    },
    build = ":TSUpdate",
    install = function()
      require("nvim-treesitter.install").setup({
        prefer_git = false,
        compilers = { "gcc" }
      })
    end,
    config = function()
      require("nvim-treesitter.configs").setup({
        auto_install = false,
        ensure_installed = {
          "c",
          "cpp"
        },
        highlight = { enable = true },
				-- そのほかの設定
		  })
		end,
	}