gvim 8 1-26 / windows 10

I'd like to use Windows Subsystem Linux (WSL)'s bash shell as a gvim's terminal instead of cmd.

So if I type in command potion of gvim: :!.\test.sh, it will echo result inside of gvim terminal - wsl's bash shell (not open a cmd window, login to bash, and then run test.sh).

Expected result would be similar to run vim inside a terminal in a linux distribution (for i.e vim under urxvt-unicode)

3 Answers 3


GVim is a 32-bit application and WSL must run on 64 bit. On Windows 10 you can use GVim with WSL if you add the following to your vimrc file:

if has("win32")
    set shell=C:\Windows\Sysnative\wsl.exe
    set shellpipe=|
    set shellredir=>
    set shellcmdflag=
  • This is golden answer, now cmd window won't pop-up each time I run a shell command. I have two questions: 1. it's a bit slow to complete the command - can we speed it up? 2. I try some plugins that would use .exe for stuff for i.e: tagbar plugin, echo error when try to invoke .exe file on window, obviously because we're redirecting to another shell wsl.exe, then I try to install ctags ver5.9 on wsl, manually tags a file under wsl: > ctags myfile.py. Back to gvim/windows toggle Tagbar gave no tags found. Jun 9, 2018 at 5:15
  • 1
    Came across this from searching around. Thank you for this helpful answer. However, if I'm not wrong, has('windows') checks if vim is compiled with support for multiple windows, and not the OS it is running on. Instead of has('windows'), one should use has('win32') or has('win64').
    – husB
    Mar 12, 2020 at 13:07
  • @husB Indeed, my mistake. should be has('win32') or has('win64'). Thanks for your feedback! I'll update the example (and even my vimrc file) Apr 2, 2020 at 13:38
  • 2
    When I do this on gvim 8.2 and WSL 2 Ubuntu I get an error: E485: Can't read file C:\Users\...\AppData\Local\Temp\VJB4EFA.tmp
    – DarkStar
    Mar 10, 2022 at 4:40

You should be able to accomplish this simply by assigning to the 'shell' setting the path of whatever Bash binary you are using.

I have a similar setup with Gvim + Cygwin and this is what I have in my _vimrc file...

set shell=c:\cygwin64\bin\bash.exe

You may need to add a bit extra if the bare shell launched by the above has, let's say, an empty PATH environment variable. For example, you could specify a bash init file like this...

set shell='c:\cygwin64\bin\bash.exe --rcfile /foo/bar/mybashrc'

...and define PATH in mybashrc.

There's an earlier answer of mine that touches upon a somewhat related topic that you can read if you need more help choosing the correct bash parameters.


After some frustrating years of trying to get gvim and WSL/ubuntu to play together I finally read through the vim documentation and figured out why it has been failing for me. The issue was the shellquote and shellxquote settings, by default it was wrapping my command with parentheses and I would get an error like "E485: Can't read file C:\Users...\AppData\Local\Temp\VJB4EFA.tmp".

Here are the settings that finally allowed this to work for me:

if has("win32") || has("win64")
    set shell=bash.exe
    set shellslash
    set shellpipe=|
    set shellredir=>
    set shellquote=\"
    set shellxquote=
    set shellcmdflag=-c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.