Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vimscript: how do I get the OS that is running Vim?

Tags:

vim

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?

like image 777
Herbert Sitz Avatar asked May 27 '11 00:05

Herbert Sitz


2 Answers

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.

like image 112
jcov Avatar answered Nov 10 '22 19:11

jcov


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.

like image 40
ZyX Avatar answered Nov 10 '22 19:11

ZyX