gpt4 book ai didi

windows - 如何判断 vim 是在命令行还是在 powershell 中运行

转载 作者:可可西里 更新时间:2023-11-01 14:42:02 24 4
gpt4 key购买 nike

我想创建一个函数来执行以下操作

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

.但我宁愿建议直接用类似的东西运行 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 中运行。

关于windows - 如何判断 vim 是在命令行还是在 powershell 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11915895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com