我想做一个function,做到以下几点
if (vim is running in powershell) call system("only works in powershell") else echo "Skipping powershell command"
有谁知道如何告诉vim正在运行什么程序?
编辑: echo &term
输出“win32”在这两种情况下。
从我看到你不需要检查什么vim运行。 您需要检查&shell
的值,因为如果&shell
命令告诉它在powershell中运行命令,vim将在powershell中运行命令。 如果shell的名字是posh
那么检查可能会完成
if stridx(&shell, 'posh')!=-1 call system('only works in powershell') else echo 'Skipping powershell command' endif
。 但我宁愿建议直接运行类似的东西
call system('posh -c '.shellescape('only works in powershell'))
(注意:我不确定'posh -c '
字符串实际应该是什么样子)还是临时设置和shell选项:
let savedsh=[&shell, &shellcmdflag, &shellxquote, &shellxescape, &shellquote, &shellpipe, &shellredir] set shell=posh shellcmdflag=-c shellxquote=\" shellquote=\" shellpipe=> shellredir=> try call system('only works in powershell') finally let [&shell, &shellcmdflag, &shellxquote, &shellxescape, &shellquote, &shellpipe, &shellredir]=savedsh endtry
(再次,不确定选项的确切值):这些方法命令将永远运行在PowerShell中。
你可以检查$term
。 比如在我的cygwin
和git bash
,我得到了$term
作为cygwin
。
对于Powershell,您可以在您的配置文件中设置以下内容并检查:
$env:TERM = "posh"
请注意, &shell
将cmd.exe和cmd.exe都包含在内。