Creating a single VIM installation for UNIX and Windows

If you're a dedicated Vim user you probably have it on every *NIX and Windows machine you own. If so, you're probably familiar with the problem of keeping your configuration files in sync. If you make a change to vimrc on one machine, how do you make it available to all the other installations on your network?

One solution is simply to serve Vim from a central location on your *NIX machine over a Samba share. The idea is to execute Vim from any Windows machine over this share, which uses the same files as a *NIX Vim.

What follows is a setup that serves Vim over a SAMBA-enabled FreeBD machine, to *NIX and Windows computers. Basically, with a few adjustments, a single common vimrc can be used by all machines.

The setup has two locations, a Startup Directory and a Vim Installation Directory.

The Startup Directory contains a common vimrc configuration file for all instances of Vim on all machines. This directory also contains launcher bats/shellscript for each execution type:

  • Gvim in a Windows window - win.bat
  • Vim in NT command window - dos.bat
  • Vim in a *NIX terminal window - unx.sh

The Vim Installation Directory contains a complete Windows installation copied from a Windows machine, and has the vim74 and vimfiles directories contained under it. The Windows installation copied to this directory is based on Pritesh Ugrankar's featured instructions which includes Pathogen installation and themes.

The Startup Directory

This should be accessible from Windows as:

\\FREEBSD\SHARE\EDITOR\_vimrc

and is, in reality the EDITOR directory of your homedir on the *NIX host:

/usr/home/<username>/EDITOR

EDITOR must be created manually, and the common _vimrc from the selected Windows installation must be placed inside it. Additionally, the following three launcher files also need to be created in this directory:

win.bat

set VIM=//FREEBSD/SHARE/EDITOR
set VIMRUNTIME=//FREEBSD/SHARE/VIM/vim74
gvim -u _vimrc -i _viminfo

dos.bat

set VIM=//FREEBSD/SHARE/EDITOR
set VIMRUNTIME=//FREEBSD/SHARE/VIM/vim74
gvim -u _vimrc -i _viminfo

unx.sh

export VIM=/home/<username>/EDITOR
export VIMRUNTIME=/usr/home/<username>/VIM/vim74
vim -u _vimrc -i _viminfo

Just substitute path and <username> in the export and set statements for your own *NIX account path.

Additionally, the top of _vimrc in this directory place the following two lines to allow Vim to properly locate its plugins

exe 'set rtp+=' . expand('../VIM/vimfiles')
exe 'set rtp+=' . expand('../VIM/autoload')

The Vim installation directory

To support remote execution of Vim on Windows which shares a common set of VIM plugins, an existing Windows installation of VIM needs to be copied into a directory on the *NIX host called:

/usr/home/<username>/VIM

This should show up as a share visible to Windows as:

\\FREEBSD\SHARE\VIM

Unfortunately, you'll have to strip out any CTRL-M (\r) line endings from *.vim files (and _vimrc), because these will prevent the *NIX shell from loading configurations.

Edits can be accomplished in place using Perl

perl -i -p -e 's/\r//' file

That's the most monotonous part of setup. Detailed diagnostics can be seen by booting Vim with the -V switch.

With this setup you should be able to execute Vim using a single set of configuration files and plugins, irrespective of whether it is being run in a DOS command shell, a Windows Window, or a *NIX shell.