簡體   English   中英

在Vim for Windows上設置Cygwin shell路徑

[英]Setting Cygwin shell path on Vim for Windows

我試圖在Windows上設置Vim,使用Git bash(Cygwin)作為shell環境。 我收到一個關於臨時文件的錯誤,我99%確定這與無法加載shell的事實有關(即“!”命令不起作用)。

在我的_vimrc文件中,我嘗試將shell選項設置為各種各樣的東西,但都不起作用。 我的cygwin / git bash命令路徑是C:\\ Program 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 = 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...

有誰知道如何設置包含空格的shell路徑?

你幾乎做對了。 你需要逃避每個周圍的“。而不是逃避空間,窗口要求你用引號括起字符串。但是vim將引用解釋為注釋。所以你需要逃避雙引號。你還需要一個反斜杠來逃避空間。

請參閱以下示例:h 'shell' (注意shell周圍的單引號是獲取shell選項的幫助所必需的。否則,您將獲得有關shell ex命令的幫助。)

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

您可以鍵入以下內容來檢查值:

:echo &shell

作為旁注 - 我建議不要在win32 gvim中使用bash / sh。 許多插件測試has("win32")並為cmd.exe而不是&shell值構造shell命令。 因此,如果shell不是cmd.exe ,這些插件將失敗。 理想情況下,這些插件會測試&shell值而不是使用has("win32") 所以,即使我從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

編輯:正如@LucHermitte在評論中提到的,當shell設置為bash或sh時,在win32 gvim上不起作用的插件應該被修復。 我同意......但根據我的經驗,這並不總是可行的。 所以我總是把shell設置回$ COMSPEC(通常是cmd.exe)。 如果你的插件沒有任何問題,那就太好了,不理會我的旁注。)

我使用以下定義從win32-gvim運行外部cygwin相關的可執行文件: https//github.com/LucHermitte/vim-system-tools/blob/master/plugin/system_utils.vim#L467 (其他shell選項)也很重要)

但是,我建議你把你的cygwin入口點放到你的%PATH%中。 這將是最簡單的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM