I share my VIM configuration file between several computers. However, I want some settings to be specific for certain computers.

For example, font sizes on the high-res laptop should be different to the low-res desktop. And more importantly, I want gVIM on Windows to behave more windowsy and MacVim on OSX to behave more maccy and gVIM on Linux to just behave like it always does. (That might be a strange sentiment, but I am very used to switch mental modes when switching OSes)

Is there a way to make a few settings in the .vimrc machine- or OS-dependent?

Also useful: has('gui_running') if you need to differentiate between tty mode and GUI mode.
–
Chris JohnsenOct 1 '10 at 13:20

9

The has() function tests the presence of Vim features. There is no 'linux' feature. The proper argument is 'unix'. Also, the proper argument for OS-X is 'macunix'. There is also a 'mac' feature, but I don't know whether has('mac') is true for all Macs or just pre-OS-X Macs. See :help feature-list for the full list.
–
garyjohnOct 1 '10 at 15:14

This simply executes source $HOME/.$HOSTNAME.vimrc if it exists. I've used hostname() and concatenation, you could also use the more succinct expand('$HOME/.$HOSTNAME.vimrc') if you know that $HOSTNAME is always set.

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.

You could just put the OS-specific stuff in a custom .gvimrc for each machine, and use a common .vimrc on all of them. Both files are read when GVim starts, only .vimrc is read when the non-gui Vim starts.