There are several different types of symlinks on Cygwin. Only the native NTFS symlink type will be understood by a non-Cygwin build of gVim.
That gives you two options, depending on which direction you want the symlink to point:
Cygwin Vim as Master, Native gVim Pointing to It
Right-click the Cygwin Terminal icon, select "Run as administrator," then give the following commands:
cd "$USERPROFILE"
CYGWIN=winsymlinks:nativestrict ln -s ~/.vim vimfiles
Now you can use Vim plugins in the Unix way, with ~/.vim
as the directory where Cygwin Vim looks for local plugins and such, with Windows gVim continuing to find them in the vimfiles
directory under your Windows user profile directory, not realizing that it is being directed through an NTFS symlink to the directory Cygwin Vim uses.
You may need to do this for .vimrc
as well. (See below for why "may.")
Although Cygwin Vim uses Unix style line endings (i.e. LF-only) for plugins and such and native Windows gVim uses DOS style (CRLF) endings, I did not find it necessary to convert the Unix line endings in my Vim configuration to DOS style to get gVim to read the files correctly. This is doubtless because Vim itself gracefully copes with such things as a text editor, so naturally it would do the same for the configuration and script files it reads.
Native gVim as Master, Cygwin Vim Pointing to It
Doing it this direction is simpler, since only Cygwin needs to understand the symlink, and because Cygwin symlinks don't have all the restrictions of NTFS symbolic links.
In a regular (i.e. non-admin) Cygwin terminal, type this command:
ln -s "$(cygpath -u "$USERPROFILE")"/vimfiles ~/.vim
Much simpler.
To be clear, there's nothing stopping you from combining both options, using an NTFS symlink to point Cygwin at a vimfiles
directory as .vim
. There's just no advantage to it over the above.
Bonus Option: Using the Cygwin Mount Table
Symlinks work fine for this purpose, but there is another option: use the Cygwin mount table. Add something like the following to your Cygwin /etc/fstab
file:
/cygdrive/c/Users/warren/vimfiles /home/warren/.vim ntfs text 0 0
Then type mount -a
at a Cygwin command prompt to make the change take effect immediately.
You will need to change the user name in both paths, of course.
This has one advantage over a symlink, which is that using a Cygwin text
mount forces Cygwin to use and accept CRLFs in text files, which reduces the mismatch between Cygwin and native Windows.
Beware, however, that this mount option can be very troublesome in practice. For this very limited purpose, I can't see any reason to choose this option, but if you find yourself needing to maintain CRLF line endings under Cygwin, you might find better uses for text mounts than this example.
Sharing More
Now, all of that is fine as far as it goes, but if you're going to try and merge the native Windows world with Cygwin in this way, you might want to take the next step by adding the following line to /etc/nsswitch.conf
:
db_home: windows
Move /etc/passwd
and /etc/group
out of the way, if you still have them, as you will if you installed Cygwin prior to 1.7.34. Then restart Cygwin, whereupon you will find that your home directory has changed from /home/$USER
to c:\Users\%USERNAME%
, a.k.a. %USERPROFILE%
.
(Naturally, you will also need to move all your per-user Cygwin files over from the old Cygwin home directory to the new one after doing this.)
Not only does that mean your Cygwin home directory now has Documents
, Downloads
, Pictures
, etc. as subdirectories, it also means native Windows gVim and Cygwin Vim will look for .vimrc
in the same location, avoiding the need to create a symlink for it, too.
(As for why a native Windows build of Vim doesn't use .vim
as the Unix and Linux builds do, that's a pre-NT restriction on path names, preventing them from starting with a dot, because dots have semantic meaning to the FAT file system, or at least to the old command.com
shell. A file name beginning with a dot under that system has no file name, only an extension, so it barfs if you try. Vim is old and portable enough for that to have mattered within its lifetime, so the coping strategy they chose way back then carries forward to today.)
Beware that you cannot combine this option with the mount table option since Cygwin will refuse to use mount points outside the Cygwin root, even if you use its cygdrive
mechanism. Presumably this is because mount points are handled at a lower level than cygdrive
within Cygwin.