1

I upgraded my Cygwin X-windows after 5 years. I found that there is no more /usr/share/vim/vimfiles, so I copied my files from the after, colors, plugin, spell, and syntax folders directly into the corresponding folders in /usr/share/vim/vim81. This is far from ideal, as it doesn't separate my custoimization files from the gvim package files.

What is the most robust way to maintain a separate tree of customization files, i.e., with minimal customization of environmental variables and paths? Is there a default location where gvim looks for a site-specific file tree that differs from the packaged ones?

Context

Like most people, my laptop is primarily used by myself. The different accounts are only so that I can work with a non-administrator account for normal stuff, i.e., not maintenance or housekeeping. In both administrator and non-administrator accounts, I want the same vim environment. Therefore, I will not be using user-specific vimrc files, run time paths, etc. These will be system-wide, hence my description of the situation as a site/machine-specific setup.

What I've found so far

I found relevant factors from :help startup. By default, my Cygwin installation does not set up $VIM, $VIMINIT, or $MYVIMRC. In this situation, according to the help, all folders in the runtimepath (rtp) setting are searched for plugins. Fortunately, /usr/share/vim/vimfiles precedes /usr/share/vim/vim81 in my rtp:

runtimepath=~/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim81,/usr/share/vim/vimfiles/after,~/.vim/after

The leading ~/vim is a holdover from an old user-specific vimrc file, before I decided to do things system-wide. It led to headaches keeping the various vimrc files synchronized. I'm going to leave it in because there may be occassion to take advantage of it, but I just won't have a ~/vim by default.

Because it is present in rtp all I have to do create /usr/share/vim/vimfiles and unpack my personal after, colors, plugin, spell, and syntax folders directly into it. According to :help rtp, all of these folders are searched for in the paths specified by rtp.

It looks like I've answered my own question, but I'd appreciate it if someone could confirm its correctness.

Mitigating pollution of virgin vim 8.1 package files

It's too late for me now. I already polluted the /usr/share/vim/vim81 file tree with my custom files. However, I think I just selectively copied files into locations wherein they did not exist. I can use bash to find the relative paths of my customization files in the vim81 tree

cd /path/to/my/customization/file/tree
for file in $( find * -type f )
do
    diff -qs $file /usr/share/vim/vim81/$file
done

Files after/ftplugin/netrw.vim and ../vim81/after/ftplugin/netrw.vim are identical
Files after/syntax/tex.vim and ../vim81/after/syntax/tex.vim are identical
Files colors/mine.vim and ../vim81/colors/mine.vim are identical
Files plugin/bufexplorer.vim and ../vim81/plugin/bufexplorer.vim are identical
Files plugin/ChristiansHi20150126.vim and ../vim81/plugin/ChristiansHi20150126.vim are identical
diff: ../vim81/spell/en.latin1.add: No such file or directory
diff: ../vim81/syntax/asy.vim: No such file or directory
Files syntax/texmf.vim and ../vim81/syntax/texmf.vim differ
diff: ../vim81/syntax/vbnet.vim: No such file or directory

Every occurrence of .. represents the absolute path /user/share/vim. The only files I copied into the vim81 tree are those found to be identical. If there is no corresponding file in the vim81 tree, it means I dispensed with copying that file because there seemed to be another file with a different name but for the same purpose, and more recent. On the other hand, if the files with the same name differed in content, it means I chose to rely on the newer file in the vim81 tree.

My custom files now exist in both vim81 and vimfiles. The command :scriptnames shows that the occurrence in vimfiles precedes the occurrence in vim81. This is good, but still redundant. I can repeat the above code pattern to locate the redundant occurrences in vim81, extract their paths, and submit them to the remove command rm:

cd /usr/share/vim/vimfiles
for file in $(find * -type f); do diff -qs $file ../vim81/$file; done 2>&1 | grep identical | sed -e 's=.* \(\S\+\) are identical=\1=' | xargs rm

As this is now a system-wide custoimization, I had to ensure that all accounts had read access to files/folders in vimfiles, and all execution rights to directories therein (so that they can actually descend into them):

cd /usr/share/vim

# Directories
find vimfiles -type d | xargs chmod a+rx,o-w
find vimfiles/ -type d | xargs ls -ldF # Visually confirm permissions

# Files
find vimfiles -type f | xargs chmod a-x,a+r
find vimfiles/ -type f | xargs ls -ldF # Visually confirm permissions
1

As you have figured out, even though a vimfiles directory isn't shipped as part of the Vim package in Cygwin, if you create one and populate it, Vim (and gVim) will use it in its search path.

This is controlled by the 'runtimepath' setting. And :help 'runtimepath' confirms that the default is:

           Unix: "$HOME/.vim,
                  $VIM/vimfiles,
                  $VIMRUNTIME,
                  $VIM/vimfiles/after,
                  $HOME/.vim/after"

Cygwin is Unix emulation on Windows, so the Unix defaults are used.

The order of entries in your 'runtimepath' corresponds exactly to the default. (You mentioned ~/.vim as a holdover from an old user-specific vimrc file, but that's actually the default, I don't think you're customizing these. If you are, maybe you don't need to. It's also normal that vimfiles and vimfiles/after come before and after $VIMRUNTIME, so that your files will have the correct priority.)

It is normal for the $VIM, $VIMRUNTIME and similar environment variables not to be set. (In effect, I haven't ever seen a situation in which those are set outside of Vim.) They're typically initialized by Vim itself. See :help $VIM for details on how these are set up.

Installing your custom files under /usr/share/vim/vimfiles is a good approach. As you also found out, you need to ensure they're world-readable, since all users will try to source them.

Regarding keeping your Cygwin installation pristine, you can try to reinstall the package that owns the Vim runtime files (I imagine the package might be called vim-runtime or similar.) From Cygwin's setup.exe you can manage Cygwin's packages and there's an option to reinstall a specific package. For complete cleanup, try to uninstall the package that ships the Vim runtimes, then remove any files left in /usr/share/vim/vim81 and finally installing that package back. (There's also a cygcheck command you can use to inspect packages in Cygwin.)

Installing, reinstalling or checking Cygwin packages is a bit off topic for Vi &Vim, consider asking on Superuser Stack Exchange if you have any follow up questions about Cygwin.

| improve this answer | |
  • 1
    Thanks for the confirmation, filbranden. You're right, my code didn't add ~/.vim to runtimepath. I have code that does it, but surrounded by flow control so that it runs only for the Windows installation of gvim (which I no longer use due to lack of bash integration). I appreciate your suggestions on keeping the installation files pristine, but I'm comfortable with how I located and removed custom files from vim81. I don't want to tempt fate by messing further. – user2153235 Jan 28 at 1:44

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.