how do I detect OS X in my .vimrc file, so certain configurations will only apply to OS X?

前端 未结 7 664
庸人自扰
庸人自扰 2020-12-12 15:18

I use my .vimrc file on my laptop (OS X) and several servers (Solaris & Linux), and could hypothetically someday use it on a Windows box. I know how to detect unix gene

7条回答
  •  猫巷女王i
    2020-12-12 15:31

    I'm doing the same thing you are. Don't try to detect the OS. Instead, try to detect the type of vi/vim.

    Check :h feature-list for a full list of the conditionals you can use.

    Here's what I use to detect MacVim in my vimrc:

    if has("gui_macvim")
      set guifont=Monaco:h13
    endif
    

    With this, you can detect for gvim, vi, vim, and whatever other flavors you might use. The nice thing is that you could have vim-compatible settings on OS X.

    Reference from Vim Mailing list

    EDIT: This approach and its variants (has('mac'), has('macunix'), has('gui_mac'))do not work for vim in OS X. If you use only use MacVim, you're safe. If you're weird like me and like to occasionally jump into vim, one of the other solutions may be more suitable.

提交回复
热议问题