Is there a command in Vimscript to get the current Operating System?

大憨熊 提交于 2019-12-23 11:36:09

问题


What the title says. I can think of some hackish ways to do it, but is there a correct way to do this?


回答1:


To check for Windows, most scripts I have seen use the following:

let s:win = has("win16") || has("win32") || has("win64")

If none of these are defined, then it is a non-windows system and you can try the uname suggestion by Martín Fixman.




回答2:


If you are sure you will use Unix-like operating system, you can use

let os = substitute(system('uname'), "\n", "", "")
if os == "SunOS"
" Do Sun-specific stuff.
...
elseif os == "Linux"
" Do Linux-specific stuff.
...
endif

You can anyway use the has() command to check if some feature is supported, for more information look

:help has()



回答3:


has('gui_macvim') has('gui_gtk2') has('gui_gtk') has('gui_win32')


来源:https://stackoverflow.com/questions/2783224/is-there-a-command-in-vimscript-to-get-the-current-operating-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!