问题
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