CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 1k
Windows support
A C compiler is required to compile the parsers needed for nvim-treesitter.
Hint: this page was written by a Linux user. So this article needs some extensions and verification by Windows users. Feel free to contact us on Matrix!
- Please extend this article
- Report issues when using the plugin with Windows
- Create a issue if you wish to be able download pre-compiled parsers with
:TSInstall
As a default, nvim-treesitter will try to use git
to download the parser packages. It is recommended to use curl
+tar
(which is the default on Linux and MacOS). curl
is bundled with Neovim and tar
(BSD tar) is bundled with recent version of Windows. To enable the curl
option you should:
require 'nvim-treesitter.install'.prefer_git = false
(Using git
is deprecated and will be removed in future versions.)
nvim-treesitter will check whether the following executables are in %PATH%
M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang", "cl", "zig" }
You can change the order in which the compiler is chosen. The following will use clang
for compiliation and gcc
if clang
is not executable.
require 'nvim-treesitter.install'.compilers = { "clang", "gcc" }
Since this is using the well tested compilers that we use on Linux/MacOS it should work fairly easy and without any surprises.
- Install git (not required on newer versions of Windows 10,
tar
is installed andcurl
is bundled with Neovim) - Install MinGW toolchain
- Via chocolatey:
choco install mingw
(in admin powershell)
- Via chocolatey:
- Start Neovim in a refreshed environment:
refreshenv
- Install parsers in Neovim via
:TSInstall c
,:TSInstall cpp
- Install git (not required on newer versions of Windows 10,
tar
is installed andcurl
is bundled with Neovim) - Install LLVM
- Via winget(recommended):
winget install -i LLVM.LLVM
(in admin powershell) - Via chocolatey:
choco install llvm
(in admin powershell)
- Via winget(recommended):
- Validate LLVM bin folder on PATH
- Start Neovim in a refreshed environment:
refreshenv
- Install parsers in Neovim via
:TSInstall c
,:TSInstall cpp
Follow the instructions at the Microsoft LLVM Support docs to install Clang through the Visual Studio Installer
This installs x86
and x64
versions of clang
. Ensure the version in your Path
is for the same architecture as Neovim, i.e. if you installed x64
Neovim, ensure the x64
version of clang
(the path will be C:\BuildTools\VC\Tools\Llvm\x64\bin
or something similar) is in your Path
.
The MSVC Toolchain can be obtained either by already having Visual Studio installed or by installing the Visual Studio Build Tools.
Ensure that Neovim is launched in an environment where cl.exe
- the MSVC C/C++ compiler - is available (e.g. Developer PowerShell/Command Prompt for VS 2022), and that the architecture of cl.exe
matches the one of Neovim (i.e. if you're using the x64 version of Neovim, you should use the x64 version of cl). From within one of the aforementioned Developer Shells, cl.exe
should be in PATH
and you can use :TSInstall c
from within Neovim.
If you wish to use cl from a different shell than the previously mentioned ones (i.e. PowerShell Core or Windows PowerShell), the easiest method is to modify your session's environment variables. You'll need to copy the values of these variables into a scratch file, then paste their values into session variables you can use.
From the Developer Shells, you'll need the values for three environment variables: PATH
, INCLUDE
, and LIB
. These have different values from your global environment variables in the Developer Shells.
In this shell, you can obtain the values of the environment variables in a few ways, but the easiest is to use Write-Host
. This line will print all three at once, each called out and separated by a newline:
Write-Host "PATH: $($env:PATH)`n`nINCLUDE: $($env:INCLUDE)`n`nLIB: $($env:LIB)"
The following line will print all three environment variables at once in a similar format to the PowerShell variant:
echo PATH: %PATH% && echo. && echo INCLUDE: %INCLUDE% && echo. && echo LIB: %LIB%
Press the Win + R key to open the Run dialog and enter sysdm.cpl. Press Enter or click OK. In the System Properties dialog, select the Advanced tab, then click the Environment Variables... button in the bottom-right. In the Environment Variables dialog, there are two sections. The top section are variables for the current user and the bottom section are for system-wide environment variables. Modify only the variables for the current user. Append the values you previously obtained for PATH
to your existing one, and add new ones for INCLUDE
and LIB
, pasting those values in respectively. Once finished, click the OK button in the Environment Variables dialog to commit the changes. You'll need to close and re-open any existing shells.
If you'd like to do something a bit more spiffy and Linux-like, you can leverage PowerShell User Session Scripts to temporarily modify the Environment Variable PSDrive.
The User Session Script is always named Microsoft.PowerShell_profile.ps1
, but it's located in different directories depending on which version of PowerShell you're using. If you're using Windows PowerShell (5.x and lower), the file is located in ~\Documents\WindowsPowerShell\
. If you're using PowerShell Core (6.x and greater), the file is located in ~\Documents\PowerShell\
. Regardless, the code to pull this off is the same for each.
Assuming you have the values for the variables from the Developer Shells, you can place the following lines in the User Session Scripts:
$Env:PATH += "Values\From\Developer\Shell"
$Env:INCLUDE = "Values\From\Developer\Shell"
$Env:LIB = "Vales\From\Developer\Shell"
The next time you run a PowerShell session, these variables will be modified only within the env:
PSDrive for the lifespan of that session.
Since it's a cross platform compiler it should work fairly easy and without any surprises.
- Install git (not required on newer versions of Windows 10,
tar
is installed andcurl
is bundled with Neovim) - Install Zig
- Via scoop:
scoop install zig
- Via scoop:
- Start Neovim
- Install parsers in Neovim via
:TSInstall c
,:TSInstall cpp
- Install git (not required on newer versions of Windows 10,
tar
is installed andcurl
is bundled with Neovim) - Install gcc
- Via scoop:
scoop install gcc
- 64 bit mingw/gcc installer: https://techdecodetutorials.com/download/
- Via scoop:
- refresh environment variables :
refreshenv
- Install parsers in Neovim via
:TSInstall c
,:TSInstall cpp
-
Some users reported that
refreshenv
was not enough for gcc to compile the files correctly. They needed a reboot. -
A successfully compiled parser has a
.so
suffix -- it can be loaded just fine. In case you are a beginner and confused with these nixy files and that the parser doesn't activate out-of-box, just follow:help nvim-treesitter
and enable the relevant modules. -
If you get one of these errors:
-
uv_dlopen
cant find module -
*.so
is not valid WIN32 application
Ensure CL.exe (MSVC) (compiled *.so files) architecture matches Nvim architecture by checking: nvim --version
or using dumpbin
on get-command nvim
, and cl --version
for x86 or x64 and ensuring you have the right environment (x86 Native Tools Command Prompt for VS 2022 vs x64 Native Tools Command Prompt for VS 2022).
Then uninstall and reinstall the parser(s).