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 generally, and windows, but how do I detect OS X? (And for that matter, is there a way to distinguish between Linux and Solaris, etc. And is there a list somewhere of all the strings that 'has' can take? My Google-fu turned up nothing.)
For instance, I'd use something like this:
if has("mac") " open a file in TextMate from vi: " nmap mate :w<CR>:!mate %<CR> elseif has("unix") " do stuff under linux and " elseif has("win32") " do stuff under windows " endif
But clearly "mac" is not the right string, nor are any of the others I tried.
UPDATE: The answer below ("macunix") seems fairly clearly like it should work, but for some reason it doesn't. (Perhaps Apple didn't compile vim properly to respond to this? Seems unlikely.)
At any rate I guess I need to shift the focus of the question: does anyone have a solution that will achieve the same ends? (That is, successfully detecting that the .vimrc file is being used on Mac OS X.)
The path used by macOS's default vim install is /usr/share/vim/vimrc .
Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.
The system vimrc should normally be left unmodified and is located in the $VIM * directory.
My updated .vimrc
now uses the following:
if has("gui_running") " Gvim if has("gui_gtk2") || has("gui_gtk3") " Linux GUI elseif has("gui_win32") " Win32/64 GVim elseif has("gui_macvim") " MacVim else echo "Unknown GUI system!!!!" endif else " Terminal vim endif
My original answer is below
You could try what I do in my .vimrc:
if has("unix") let s:uname = system("uname -s") if s:uname == "Darwin" " Do Mac stuff here endif endif
Although, to be completely transparent, my actual .vimrc reads:
let s:uname = system("echo -n \"$(uname)\"") if !v:shell_error && s:uname == "Linux"
Mainly for detecting Linux (as opposed to OSX)
I'm not sure if you absolutely have to do that echo -n \"$(uname)\"
stuff, but it had to do with the newline at the end of the uname
call. Your mileage may vary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With