3

I have a cygwin shell in my windows computer and it has a Vim installation of its own in it. And, so the plugins I have for Gvim are not available for the Cygwin vim.

I tried symlinking the plugins from cygwin to the gvim but Vim is complaining about the File's line endings.

So, Is it possible to use the same plugin folders for both vim inside cygwin and vim in windows with out the file ending conflict?

2

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.

  • I am getting that error when I tried it the second way. Is there an option that i can for the symlink so that the Cygwin's vim can read the plugins with conversion to linux endings without actually changing the original plugin files? – Durga Swaroop Jul 3 '16 at 0:03
  • Windows can do that? Ok. I'll try. And, sorry for the confusion though. – Durga Swaroop Jul 3 '16 at 0:06
  • 1
    I simlink ~/.vim to ~/vimfiles (the homes may be different between Windows and Cygwin) and convert all the files under that directory to have Unix line endings, and all the files work fine under both Windows and Cygwin. I think the Cygwin utility to do that is u2d or maybe unix2dos. – garyjohn Jul 3 '16 at 6:56
  • @garyjohn I tried that. I have kept the plugin folder in cygwin's vim home and symlinked it to Window's vim. The link is created properly and Cygwin's vim is able to use the plugin but Vim on windows is detecting that at all. Is there something I am missing here? – Durga Swaroop Jul 5 '16 at 9:07
  • I just noticed an error in my comment above: The Cygwin conversion utility is d2u or dos2unix. Windows Vim handles either but Unix (e.g., Cygwin) Vim requires Unix line endings. – garyjohn Jul 6 '16 at 5:15

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.