I've got vim plugin that runs on different machines and sometimes needs to do things differently depending on whether it's Windows, Linux, Mac.
What's easiest way to test for the operating system? I know I could parse the output of :version command. Is there something simpler that will reveal the OS?
From google:
You can use has()
and the list of features under :help feature-list
to
determine what type of Vim (and therefore under which OS is running).
if has('win32')
... win32 specific stuff ...
endif
Search for "version of Vim" from the feature-list help topic and that should bring you to the different versions for which you can check.
In addition to @John's answer here is a full list of possible operating systems:
"▶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
This is the code used by my frawor plugin for determining current operating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With