简体   繁体   English

在Vim for Windows上设置Cygwin shell路径

[英]Setting Cygwin shell path on Vim for Windows

I am attempting to set up Vim on Windows, using Git bash (Cygwin) as the shell environment. 我试图在Windows上设置Vim,使用Git bash(Cygwin)作为shell环境。 I'm getting an error about temporary files which I'm 99% sure is related to the fact that the shell can't be loaded (ie the "!" commands don't work). 我收到一个关于临时文件的错误,我99%确定这与无法加载shell的事实有关(即“!”命令不起作用)。

In my _vimrc file I've tried setting the shell option to be various things, none of which work. 在我的_vimrc文件中,我尝试将shell选项设置为各种各样的东西,但都不起作用。 My cygwin/git bash command path is C:\\Program Files\\Git\\bin\\sh.exe , and the space seems to be causing problems. 我的cygwin / git bash命令路径是C:\\ Program Files \\ Git \\ bin \\ sh.exe ,这个空间似乎导致了问题。 I've tried the following, without success: 我尝试了以下内容,没有成功:

:set shell=C:\Program Files\Git\bin\sh.exe    " Error = Unknown options: Files/Git/bin/sh.exe

:set shell=C:/Program Files/Git/bin/sh.exe    " Error = Unknown options: Files/Git/bin/sh.exe

:set shell="C:/Program Files/Git/bin/sh.exe"  " Error when running a command: shell option is empty

:set shell=C:/Program\ Files/Git/bin/sh.exe   " Error when running a command: 'C:/Program' is not recognized as an internal or external command...

Does anyone know how I can set a shell path that contains a space? 有谁知道如何设置包含空格的shell路径?

You almost got it right. 你几乎做对了。 You need to escape each surrounding ". Instead of escaping a space, windows requires you to wrap the string in quotes. But vim interprets the quote as a comment. So you need to escape the double quote. You also need a backslash to escape the space. 你需要逃避每个周围的“。而不是逃避空间,窗口要求你用引号括起字符串。但是vim将引用解释为注释。所以你需要逃避双引号。你还需要一个反斜杠来逃避空间。

See an example in :h 'shell' (note the single quotes around shell is necessary to get help on the shell option. Otherwise you get help on the shell ex command.) 请参阅以下示例:h 'shell' (注意shell周围的单引号是获取shell选项的帮助所必需的。否则,您将获得有关shell ex命令的帮助。)

:set shell=\"C:\Program\ Files\Git\bin\sh.exe\"

You can check the value by typing: 您可以键入以下内容来检查值:

:echo &shell

As a side note though - I recommend not using bash/sh inside the win32 gvim. 作为旁注 - 我建议不要在win32 gvim中使用bash / sh。 Many plugins test for has("win32") and construct shell commands for cmd.exe rather than the &shell value. 许多插件测试has("win32")并为cmd.exe而不是&shell值构造shell命令。 As a result, these plugins will fail if the shell is not cmd.exe . 因此,如果shell不是cmd.exe ,这些插件将失败。 Ideally these plugins would test the &shell value rather than using has("win32") . 理想情况下,这些插件会测试&shell值而不是使用has("win32") So even though I call win32 gvim from inside cygwin, I always set the shell back to cmd.exe or better $COMSPEC using this snippet in my vimrc. 所以,即使我从cygwin中调用win32 gvim,我总是将shell设置回我的vimrc中使用此代码段的cmd.exe或更好的$COMSPEC

if has("win32") || has("win64") || has("win16")
  "I do other stuff in here...

  "Then only inside this if block for windows, I test the shell value
  "On windows, if called from cygwin or msys, the shell needs to be changed to cmd.exe
  if &shell=~#'bash$'
    set shell=$COMSPEC " sets shell to correct path for cmd.exe
  endif
endif

Edit: As @LucHermitte mentions in the comment, plugins that don't work on win32 gvim when shell is set to bash or sh should be fixed. 编辑:正如@LucHermitte在评论中提到的,当shell设置为bash或sh时,在win32 gvim上不起作用的插件应该被修复。 I agree... but in my experience this was not always feasible. 我同意......但根据我的经验,这并不总是可行的。 So I always set the shell back to $COMSPEC (cmd.exe usually). 所以我总是把shell设置回$ COMSPEC(通常是cmd.exe)。 If you don't have any issues with your plugins, then that's great and ignore my side note.) 如果你的插件没有任何问题,那就太好了,不理会我的旁注。)

I'm using the following definitions to run external cygwin related executables from win32-gvim: https://github.com/LucHermitte/vim-system-tools/blob/master/plugin/system_utils.vim#L467 (the other shell options are also quite important) 我使用以下定义从win32-gvim运行外部cygwin相关的可执行文件: https//github.com/LucHermitte/vim-system-tools/blob/master/plugin/system_utils.vim#L467 (其他shell选项)也很重要)

But, I recommend you to put your cygwin entry-point into your %PATH%. 但是,我建议你把你的cygwin入口点放到你的%PATH%中。 This will be the easiest way. 这将是最简单的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM