Is there a command in Vimscript to get the current operating system?

What the name says. I can come up with some hacker ways to do this, but is there a right way to do this?

+4
source share
3 answers

To check for Windows, most of the scripts I've seen use the following:

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

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

+5
source

If you are sure that you will use a 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 

In any case, you can use the has () command to check if any function is supported; for more information, see

 :help has() 
+4
source
 has('gui_macvim') has('gui_gtk2') has('gui_gtk') has('gui_win32') 
+1
source

Source: https://habr.com/ru/post/1309036/


All Articles