I'm looking for a way to make a single configuration file both for windows platform and for unix one. So for now i have two configs .vimrc for unix and _vimrc for windows platform and the only difference between them is a necessary commands to vundle plugin manager. (i desregard the difference with filename, as i aim only to store a common version of file on my dotfiles repo and symlink with the right name at place)


set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#rc()
Plugin 'VundleVim/Vundle.vim'
call vundle#end()


set rtp+=$HOME/vimfiles/bundle/Vundle.vim/
call vundle#begin('$USERPROFILE/vimfiles/bundle/')
Plugin 'VundleVim/Vundle.vim
call vundle#end()

So it's boring to maintain changes in both as i'm working on linux as well on windows platform. I guess i could do operating system detection like if has("win32") but i think it's not a good idea to wrap every system dependent statement in construction like this. I'm wondering if there any option to this and how you deal with this.

  • 1
    Does the .vimrc have an "include" syntax that could be made conditional on OS? You could keep everything common in one file, and then have an include for unix-specific and an include for windows-specific. That way you would only have one "if" structure, and all the stuff specific to a given OS would be in its respective file. – msouth Jan 23 '18 at 9:14
  • 5
    I don't understand your objection to wrapping the system dependent statements in an if block that checks the operating system. Why do you think this is a bad idea? – Rich Jan 23 '18 at 9:39
  • I agree with msouth comment: in your vimrc define a variable containing an OS-dependent path let $MYLOCALVIMRC = has('win32') ? "~/_windows.vim" : "~/.unix.vim" then you can test if the file exists (if filereadable($MYLOCALVIMRC)) and source it (source $MYLOCALVIMRC). It works pretty well I use that in my own vimrc. – statox Jan 23 '18 at 12:16
  • Yes, i've construction like this in my vimrc if has("win32") set rtp+=$HOME/vimfiles/bundle/Vundle.vim/ call vundle#begin('$USERPROFILE/vimfiles/bundle/') else set rtp+=~/.vim/bundle/Vundle.vim/ call vundle#rc() endif but it's only requirement of plugin. May be someone has configuration with two lines - one for rtp and another for the procedure start. If not i will keep on with this config. – Dmitrii Jan 23 '18 at 12:41
  • Actually at the time i was making this question i was sure that only me how do with Vundle like this, but if it's wide practice than ok. – Dmitrii Jan 23 '18 at 12:52

If you are already using symlinks to set up your Vim configuration, and if — as I infer from your comments — the only operating system dependent part of your current config is your Vundle setup, then you don't actually need any special code in your vimrc:

Windows Command Line

:: You'll already be setting up this symlink
mklink /D %HOMEDRIVE%%HOMEPATH%\vimfiles <path_to_repo\vimfiles>

:: Set up another link for access via "~/.vim" path
mklink /D %HOMEDRIVE%%HOMEPATH%\.vim <path_to_repo\vimfiles>

N.B. Instead of creating two symlinks, you could fiddle with 'runtimepath', but the above seems simpler to me.

Unix Shell

:: You'll already be setting up this symlink
ln -s <path_to_repo/vimfiles> ~/.vim


" This code will now work on both Unix and Windows
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

N.B. ~ can be used in options on both Windows and Unix. See :help $HOME.

If you remove the leading _ or . from your vimrc filename you won't need to symlink it separately: you can just place it inside your .vim directory (See :help vimrc):

  • Yes, i changed my congig like this. So on windows i clone Vundle in .vim directory but symlink has to be with underscore at beginning as i use gvim which requires this, anyway it's not a big problem. Don't know why i used vimfiles directory before, i thought it was required by vundle. Thanks. – Dmitrii Jan 25 '18 at 9:13
  • @Dmitrii Windows Vim expects you to use ~/vimfiles for your configuration. It doesn't care if this is a real directory or a symlink to a directory elsewhere. I'm suggesting you also symlink .vim to the same source location, so on Windows ~/vimfiles and ~/.vim point to the same directory. – Rich Jan 25 '18 at 10:01
  • @Dmitrii Gvim doesn't have any special requirements about using an underscore. It does the same thing that Vim does: first it checks if ~/_vimrc exists, and if it doesn't find it, it then checks for ~/vimfiles/vimrc (which, after setting up your directory symlink, will be equivalent to ~/.vim/vimrc). Unix also searches in that location, so you don't need separate/different symlinks for the vimrc file. – Rich Jan 25 '18 at 10:05
  • @Dmitrii I was presuming you were placing your entire .vim directory in your dotfiles repo. If only your vimrc is in the repo then you'll obviously still need to symlink it! – Rich Jan 25 '18 at 10:09
  • Yes i only store my vimrc and simple install script which installs vundle first, then making necessary symlinks and then i manually insatll what i need. And it's only vimrc file without underscore and symlink with underscore at home. – Dmitrii Jan 25 '18 at 10:17

As it turned out there are common practice to wrap platform specific options in statements which checks the system and set properties accrodingly to this. For some could be convenient to separate such statements into different files. As to me i end up with this:

if has("win32")
  set rtp+=$HOME/vimfiles/bundle/Vundle.vim/
  call vundle#begin('$USERPROFILE/vimfiles/bundle/')
  set rtp+=~/.vim/bundle/Vundle.vim/
  call vundle#rc()

So i made changes in single vimrc and symlink it depending on platform.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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