Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use Vim on both OS X and Windows, with almost identical configuration.

I would like to be able to use the same .vimrc on the two operating systems, but there are a couple of things I need to configure differently.

What I'd like to add to my .vimrc file is:

:if <windows>
  "some windows-specific settings here
:elseif <os x>
  "some os x-specific settings here

But I don't know what to use for <windows> and <os x>.

Is this possible?

share|improve this question
up vote 14 down vote accepted

N.B. Although both previous answers gave me enough information to figure out how to solve the problem (and received upvotes from me), neither actually gave the full answer. So that others with the same question don't have to do the research, I'm adding my own answer. However, if @googletorp or @Azz edit their answer to include this info, I'll remove my answer and accept theirs.

The output to :h feature-list suggests that you should be able to use has("win32") and has("macunix"), but the latter didn't work for me.

Here is what I ended up using:

if has("win32")
  "Windows options here
  if has("unix")
    let s:uname = system("uname")
    if s:uname == "Darwin\n"
      "Mac options here

Note that has("win32") worked for me, even in 64 bit Vim on 64 bit Windows.

You could also use similar tests of uname within the if has("unix") block to distinguish other flavours of Unix. Just run uname or uname -a from the command-line to see what you need to compare s:uname with. See also :h matchstr() if you need to compare just a part of uname's output.

share|improve this answer

You can take a look here

Basically, you can use either has(), system():

let os = substitute(system('uname'), "\n", "", "")
if os == "SunOS"
share|improve this answer

This seems to be what you're after, I don't quite understand it so I'll just link you.

share|improve this answer
Strange. That seems to be scraped from – Rich Sep 27 '10 at 15:13
@Rich: All SU data is licensed under Creative Commons Attribution ShareAlike, which they seem to adhere to. – Daniel Beck Sep 28 '10 at 15:17
@Daniel: Interesting! Thanks for letting me know. – Rich Sep 30 '10 at 10:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.