I am trying to set the shell to git bash in my vimrc.

I have this: enter image description here

The code says:

set shell=C:\Program Files\Git\git-bash.exe

But because there's a whitespace in Program Files, it acts as a separate command.

How do I go about adding an actual space character?

1 Answer 1


You have to enclose it with quotes " and escape the space:

set shell=\"C:\Program\ Files\Git\gi-bash.exe\"

Here is what the documentation says:

:help 'shell'
'shell' 'sh'        string  (default $SHELL or "sh", Win32: "cmd.exe")
    If the name of the shell contains a space, you need to enclose it in
    quotes and escape the space.  Example with quotes: >
        :set shell=\"c:\program\ files\unix\sh.exe\"\ -f
<   Note the backslash before each quote (to avoid starting a comment) and
    each space (to avoid ending the option value).  Also note that the
    "-f" is not inside the quotes, because it is not part of the command
    name.  Vim automagically recognizes the backslashes that are path
    Example with escaped space (Vim will do this when initializing the
    option from $SHELL): >
        :set shell=/bin/with\\\ space/sh
<   The resulting value of 'shell' is "/bin/with\ space/sh", two
    backslashes are consumed by `:set`.

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.