Vim Tips Wiki
Register
Advertisement
Tip 973 Printable Monobook Previous Next

created August 15, 2005 · complexity basic · author Tony Mechelynck · version 5.7


It is possible to keep native-Windows and Cygwin versions of Vim on a same machine with common runtime files (I have done it; but see Run native-Windows Vim from cygwin without a wrapper for an alternative solution). Here is what you need to do for that:

1. Install the full Windows distribution in C:\Program Files\vim\vim## where ## is the version (e.g. 63 for Vim 6.3, or 70aa for Vim 7.00aa ALPHA).

2. Install the cygwin executables (of the same version and sub-version; the patchlevel may be different), in /bin; don't install the "cygwin runtime files".

Repeat either step 1 or step 2 at each upgrade.

3. Set VIM (in the Windows environment) to C:\Program Files\vim and HOME to your home directory

4. In the cygwin startup files (e.g. ~/.bash_profile) add the following lines:

export VIM=`cygpath -u $VIM`
export HOME=`cygpath -u $HOME`

5. All runtime files must be in Unix format. If they aren't, do the following in vim (version 7 or later) for native-Windows (it takes some time but it's fairly automatic). (On version 6 it's possible but since ** wildcards are not recognised it is more work.) (See also Installing several releases in parallel, even with matchit about how to install several _different_ versions in parallel.)

:set nomore
:args $VIM/**/*.vim
:argdo setl ff=unix
:args $VIM/**/*.txt
:argdo setl modifiable noro ff=unix
:set more

6. Directories $HOME/vimfiles and $HOME/.vim must be made identical. This can be done in Cygwin bash with the following command:

cd ~
ln -s vimfiles .vim

Steps 3 to 6 need be done only once, they remain valid even if you later install a different version.

Comments[]

Note: Cygwin is a "Unix-like" OS, Windows is a "Dos-like" OS. With the above tip, you will use a common _vimrc (and common user plugins) for both. Any differences can be resolved by using

if has("unix")
  " cygwin-specific code
else
  " native-windows-specific code
endif

or even (e.g. if, in addition to this, you use dual-boot)

if has("unix")
  " code common to Cygwin and Linux
  if has("win32unix")
    " code for Cygwin but not Linux
  else
    " code for Linux but not Cygwin
  endif
elseif has("win32")
  " code for windows-native Vim
else
  echoerr "Unknown OS"
endif

See :help has() and :help feature-list for more examples.


Advertisement