据我所知,你不需要检查 vim 是从什么运行的。您需要检查的值&shell
因为 vim 会在 powershell 中运行命令,如果&shell
选项告诉它在 powershell 中运行命令。如果 shell 的名称是posh
然后检查可以通过
if stridx(&shell, 'posh')!=-1
call system('only works in powershell')
else
echo 'Skipping powershell command'
endif
。但我宁愿建议直接运行 powershell 类似
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 中运行。