Vimscript:如何获得运行Vim的操作系统?

Her*_*itz 10 vim

我有vim插件可以在不同的机器上运行,有时需要根据它是Windows,Linux,Mac来做不同的事情.

测试操作系统最简单的方法是什么?我知道我可以解析:version命令的输出.是否有更简单的东西可以揭示操作系统?

小智 14

来自谷歌:您可以使用has()和下面的功能列表:help feature-list来确定什么类型的Vim(以及因此运行的操作系统).

if has('win32')
   ... win32 specific stuff ...
endif
Run Code Online (Sandbox Code Playgroud)

从功能列表帮助主题中搜索"Vim版本",这将带您进入可以检查的不同版本.


ZyX*_*ZyX 7

除了@ John的答案之外,还有可能的操作系统的完整列表:

"?2 os.fullname
for s:os.fullname in ["unix", "win16", "win32", "win64", "win32unix", "win95",
            \         "mac", "macunix", "amiga", "os2", "qnx", "beos", "vms"]
    if has(s:os.fullname)
        break
    endif
    let s:os.fullname='unknown'
endfor
"?2 os.name
if s:os.fullname[-3:] is 'nix' || s:os.fullname[:2] is 'mac' ||
            \s:os.fullname is 'qnx' || s:os.fullname is 'vms'
    let s:os.name='posix'
elseif s:os.fullname[:2] is 'win'
    let s:os.name='nt'
elseif s:os.fullname is 'os2'
    let s:os.name='os2'
else
    let s:os.name='other'
endif
"?2
Run Code Online (Sandbox Code Playgroud)

这是我的frawor插件用于确定当前操作系统的代码.