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

标签 windows powershell vim

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

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/

相关文章:

windows - 如何在没有 "UNC path are not supported"消息的情况下从网络共享运行批处理文件?

什么都不做的 Windows 可执行文件

powershell - Powershell如何设置高级硬盘电源设置

vim - Windows 7 中的 NerdTree 复制命令

vim - 将 Vim 版本信息复制到剪贴板

java - 如何在不列出文件的情况下获取 Windows 计算机文件数?

c++ - 恢复中止的下载?

powershell - 如何检查在 Windows Server 2008 R2 上启用了哪个 SMB 版本

powershell - 如何使用powershell select字符串获取正则表达式周围的部分?

regex - vi 中包含一组字符串的任何排列的匹配行