Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

vi

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

like image 587
Paul Wicks Avatar asked May 06 '10 17:05

Paul Wicks


3 Answers

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.

like image 197
Tim Henigan Avatar answered Nov 15 '22 09:11

Tim Henigan


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()
like image 30
Martín Fixman Avatar answered Nov 15 '22 10:11

Martín Fixman


has('gui_macvim') has('gui_gtk2') has('gui_gtk') has('gui_win32')
like image 35
salceson Avatar answered Nov 15 '22 10:11

salceson