在Windows上是否可以让vim使用正斜杠?

8

在Windows上使用ViM的本地构建会在文件路径中使用反斜杠,包括自动补全,但是如果我手动使用正斜杠,则可以正常工作(实际上所有的Windows API都可以理解它们,cmd.exe是唯一的例外),而反斜杠会引起各种问题,因为它们同时兼具转义和“不用想就知道”逻辑。例如:

:vimgrep /Foo/ src/*

这很好用,但是

:vimgrep /Foo/ src\*

无法,因为反斜杠\会转义星号*。手动输入时我只写正斜杠,但是标签补全总是在末尾给出反斜杠,所以我不得不一直更改。

是否有可能重新配置ViM默认使用正斜杠(最好不需要重新编译)?

1个回答

12

这将按照您的要求完成

:set shellslash

以下是复制的帮助信息(:h shellslash)

                        'shellslash' 'ssl' 'noshellslash' 'nossl'
'shellslash' 'ssl'      boolean (default off)
                        global 
                        {not in Vi} {only for MSDOS, MS-Windows and OS/2}
        When set, a forward slash is used when expanding file names.  This is
        useful when a Unix-like shell is used instead of command.com or
        cmd.exe.  Backward slashes can still be typed, but they are changed to
        forward slashes by Vim.
        Note that setting or resetting this option has no effect for some
        existing file names, thus this option needs to be set before opening
        any file for best results.  This might change in the future.
        'shellslash' only works when a backslash can be used as a path
        separator.  To test if this is so use: 
                if exists('+shellslash')

4
注意,然而,“shellslash”会破坏一些外部程序、很多插件和shellescape()函数。因此,如果你在使用这些功能时出现奇怪的错误,请尝试禁用该选项看问题是否解决。如果某个插件受到影响,请通知插件作者。 - Ben

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接