I use the same versioned .vimrc on several machines.

Is there a way of customise that file to enable/disable a plugin based on machine name or something like that?

As example, I have something like that in my .bash_profile:

# common things

if [[ $(uname) == "Darwin" ]]
     # mac settings
     # linux settings
  • I think this is a duplicate: vi.stackexchange.com/q/4721/1841 or at least pretty related. The idea is to put a customized vimrc on each machine containing its own plugins.
    – statox
    May 6 '16 at 13:14
  • Yes, and I think keeping a separate machine-specific file is the most robust/hassle free way to go. The .vimrc doesn't have to "know" anything about which machine it is on; and, you would never touch your .vimrc file directly ever again, except to update all of them together, avoiding the chance to accidentally get them out of sync.
    – jpaugh
    May 7 '16 at 1:27

You can access your environment variable and external command from vim, so you can do:

if system('uname') =~ "Darwin"
     echo 'mac'
     echo 'other'

Note that you can use =~ instead of == to match the regex instead of the exact string (on my machine, uname gives me a newline).


if exists('$TMUX')
  echo 'in tmux'
  echo 'not in tmux'

In order not to depend on external commands my suggestion would be to use something like the following:

if has('mac')
     echo 'mac'
elseif has('win32') || has('win64')
     echo 'windows'
elseif has('unix')
     echo 'unix/linux'
     echo 'something else'
  • This works in MacVim, but not in the version included in macOS, where has('mac') (and has('macunix')) both return 0. (Tested most recently in High Sierra).
    – Rich
    Mar 2 '18 at 10:03

Provided that you (or your system) can export the environmental variables that you need, you can do something like this in your .vimrc (here I use the vim-plug plugin manager as an example, and HOSTNAME is the exported variable you want to check):

filetype off
call plug#begin('~/.vim/plugged')
if executable('ctags') && $HOSTNAME == 'macintosh'
    Plug 'Shougo/unite-outline'
    Plug 'tsukkee/unite-tag'
    Plug 'ludovicchabant/vim-gutentags'
call plug#end()

It's also common to use has() (e.g. has ("gui_running") or has ("python")) to decide to install certain plugins.


This is not a direct answer to the question, but I think is still a reasonable solution.

The way I handle this is I have several .vimrc files:

  • vimrc-all - All common things
  • vimrc-win - Windows configuration
  • vimrc-linux - Linux configuration
  • vimrc-workMachine - Things specific to my work machine
  • vimrc-homeMachine - Things specific to my home machine

On my workMachine, I create a symlink from ~/.vimrc to ~/dotfiles/vimConfig/vimrc-workMachine.

This is what my vimrc-workMachine looks like:

" ======================================
" Source general vim config
" ======================================
source ~/dotfiles/vimConfig/vimrc-all.vim
source ~/dotfiles/vimConfig/vimrc-linux.vim

" ======================================
" All other stuff
" ======================================

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