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)


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("windows")
    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. – Tuyen Pham Jun 9 '18 at 5:15

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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