shellescape() doesn't work in Windows with 'shellslash' set

97 views
Skip to first unread message

Benjamin Fritz

unread,
Dec 1, 2009, 1:45:23 PM12/1/09
to vim_dev
Since Windows' cmd.exe handles forward slash perfectly well, and
things like wildcards in file names do NOT work with backslashes, I
have 'shellslash' set in my _vimrc in Windows. I have recently ran
into the following problem:

Launch Vim in Windows XP with:

gvim -N -u NONE -i NONE

:echo shellescape('C:/Program Files/Vim')
-> "C:/Program Files/Vim"

:set shellslash
:echo shellescape('C:/Program Files/Vim')
-> 'C:/Program Files/Vim'

The latter obviously will NOT work in cmd.exe.

It looks like this is intentional behavior. From :help shellescape() :

On MS-Windows and MS-DOS, when 'shellslash' is not set, it
will enclose {string} in double quotes and double all double
quotes within {string}.
For other systems, it will enclose {string} in single quotes
and replace all "'" with "'\''".

This does not make any sense to me. Presumably, this is an attempt to
allow shellescape to work as expected on *nix-style shells running on
Windows, but isn't the 'shell' option better to use than 'shellslash'?
Other options such as 'shellxquote' depend on 'shell' rather that
'shellslash'.

Does anyone know the reasoning behind the shellescape behavior? Is
there any situation where using 'shell' instead of 'shellslash' would
NOT be better?

I can work around this by saving, resetting, and restoring the value
of shellslash around any command using shellescape, but I'm worried
about plugin behavior, etc., and it's quite a hassle.
Reply all
Reply to author
Forward
0 new messages