Custom filetype.vim in shared config Win32/Cygwin

26 views
Skip to first unread message

Michael Ludwig

unread,
Dec 14, 2008, 1:11:32 PM12/14/08
to vim...@googlegroups.com
I'm running Windows XP pluc Cygwin, maintaining my Vim configuration in
the Cygwin home directory, and sourcing it from Windows.

C:\ :: type "%userprofile%\_vimrc"
set nocompatible
" source $VIMRUNTIME/vimrc_example.vim
" source $VIMRUNTIME/mswin.vim
" behave mswin
" Konfiguration von Cygwin einlesen
source C:\cygwin\home\michael\repos5ak\config\.vimrc

And then, in the Cygwin .vimrc, I prepend the Cygwin .vim directory to
Vim's runtimepath, so that it is searched first:

if has("win32")
set runtimepath=C:/cygwin/home/michael/repos5ak/config/.vim,$VIMRUNTIME
endif
" runtimepath patched, now turn filetypes on
filetype on

This setup works, but not 100%. I have a custom "filetype.vim", and when
running Vim from the Windows environment (as opposed to the Cygwin
environment), this custom file is read after the homonymous file from
the Vim distribution. This matters, because, as documented in "help
new-filetype", section C, there has to be a test in order to prevent
loading the file twice.

type C:\cygwin\home\michael\repos5ak\config\.vim\filetype.vim
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
autocmd! BufRead,BufNewFile *.pp setfiletype PASCAL
augroup end

The loading order can be seen by entering ":script". On Cygwin:

1: /home/michael/.vimrc
2: /usr/share/vim/vim71/syntax/syntax.vim
3: /usr/share/vim/vim71/syntax/synload.vim
4: /usr/share/vim/vim71/syntax/syncolor.vim
5: /home/michael/repos5ak/config/.vim/filetype.vim # custom first
6: /usr/share/vim/vim71/filetype.vim # system second
7: /usr/share/vim/vim71/ftplugin.vim
8: /usr/share/vim/vim71/indent.vim
9: /home/michael/repos5ak/config/.vim/abbreviations.vim
10: /home/michael/repos5ak/config/.vim/noeol.vim
11: /usr/share/vim/vim71/plugin/getscriptPlugin.vim
[...]
22: /usr/share/vim/vim71/ftplugin/mail.vim

But on Windows, "filetype.vim" is first loaded from the Vim
distribution directory:

1: C:\Dokumente und Einstellungen\michael\_vimrc
2: C:\cygwin\home\michael\repos5ak\config\.vimrc
3: C:\Programme\Vim\vim72\syntax\syntax.vim
4: C:\Programme\Vim\vim72\syntax\synload.vim
5: C:\Programme\Vim\vim72\syntax\syncolor.vim
6: C:\Programme\Vim\vim72\filetype.vim # system
7: C:\cygwin\home\michael\repos5ak\config\.vim\filetype.vim # custom
8: C:\Programme\Vim\vim72\ftplugin.vim
9: C:\Programme\Vim\vim72\indent.vim
10: C:\cygwin\home\michael\repos5ak\config\.vim\abbreviations.vim
11: C:\cygwin\home\michael\repos5ak\config\.vim\noeol.vim
12: C:\Programme\Vim\vim72\plugin\getscriptPlugin.vim
[...]
22: C:\Programme\Vim\vim72\scripts.vim

Prepending the Cygwin directory to the runtimepath as seen above does
not seem to make Vim load the "filetype.vim" before the "filetype.vim"
from the Vim distribution directory. The effect is not different from
appending the directory to the end of the list, like this:

runtimepath+=C:/cygwin/home/michael/repos5ak/config/.vim

How can I make the Windows Vim read the "filetype.vim" from the
Cygwin .vim directory before the "filetype.vim" from the distribution
directory?

Thanks for any pointers.

Michael Ludwig

Ben Schmidt

unread,
Dec 14, 2008, 5:59:30 PM12/14/08
to vim...@googlegroups.com
Michael Ludwig wrote:
> I'm running Windows XP pluc Cygwin, maintaining my Vim configuration in
> the Cygwin home directory, and sourcing it from Windows.
>
> C:\ :: type "%userprofile%\_vimrc"
> set nocompatible
[...]

> source C:\cygwin\home\michael\repos5ak\config\.vimrc

> The loading order can be seen by entering ":script". On Cygwin:

Is C:\cygwin\home\michael\repos5ak\config the same location as
/home/michael? Does C:\cygwin\home\michael\repos5ak\config\.vimrc
have the same content as /home/michael/.vimrc? Perhaps you are
inadvertently sourcing different files, and you should be sourcing
C:\cygwin\home\michael\.vimrc? That would explain why the results are
unchanged when you change that file.

Can you manually check the values of all the relevant options and
variables are as you expect after starting Vim in both cases?:

:echo $HOME
:echo $VIM
:echo $VIMRUNTIME
:echo &rtp

I expect it is some kind of configuration problem, as looking at Vim's
source code, there is no reason I can see why the runtimepath order
would go wrong.

Your runtimepath is far from ideal, too. Something more like this would
be better:

let $HOME=C:/cygwin/home/michael/repos5ak/config
set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after

Most importantly, it keeps the after-directory in the list. The
system-wide vimfiles is also included. Advice you get on this list, on
the tips Wiki, in the help, etc. will assume you have a runtimepath much
like this.

Ben.

Michael Ludwig

unread,
Dec 14, 2008, 6:54:03 PM12/14/08
to vim...@googlegroups.com
Ben Schmidt schrieb am 15.12.2008 um 09:59:30 (+1100):
> Michael Ludwig wrote:
>> I'm running Windows XP pluc Cygwin, maintaining my Vim configuration
>> in the Cygwin home directory, and sourcing it from Windows.
>>
>> C:\ :: type "%userprofile%\_vimrc"
>> set nocompatible
>[...]
>> source C:\cygwin\home\michael\repos5ak\config\.vimrc
>
>> The loading order can be seen by entering ":script". On Cygwin:

>> 5: /home/michael/repos5ak/config/.vim/filetype.vim # custom first


>> 6: /usr/share/vim/vim71/filetype.vim # system second

>> But on Windows, "filetype.vim" is first loaded from the Vim
>> distribution directory:

>> 6: C:\Programme\Vim\vim72\filetype.vim # system


>> 7: C:\cygwin\home\michael\repos5ak\config\.vim\filetype.vim # custom

> Is C:\cygwin\home\michael\repos5ak\config the same location as
> /home/michael?

They're symlinked:

michael@wladimir:~ :-) ls -ld .vim*
lrwxrwxrwx 1 michael Kein 11 Aug 11 2007 .vim -> config/.vim
-rw------- 1 michael Kein 8324 Dec 14 21:42 .viminfo
lrwxrwxrwx 1 michael Kein 13 Feb 22 2006 .vimrc -> config/.vimrc

I know, I know, it's not a real symlink; we're on NTFS, so it's a
shortcut file.

C:\cygwin\home\michael :: dir .vim*
11.08.2007 17:32 527 .vim.lnk
14.12.2008 21:42 8.324 .viminfo
22.02.2006 21:27 407 .vimrc.lnk
3 Datei(en) 9.258 Bytes

To Cygwin applications, these are symlinks. The Windows Vim, however,
can't work with the shortcut file; it needs the real path, so that's
what I feed it.

> Does C:\cygwin\home\michael\repos5ak\config\.vimrc have the same
> content as /home/michael/.vimrc?

Yes, because the latter is a symlink to the former.

> Perhaps you are inadvertently sourcing different files, and you should
> be sourcing C:\cygwin\home\michael\.vimrc? That would explain why the
> results are unchanged when you change that file.

Changes in my Cygwin .vimrc are reflected in both the Cygwin and the
Windows Vim. The only thing I'm aware of that doesn't work is the
"filetype.vim" resolution order.

> Can you manually check the values of all the relevant options and
> variables are as you expect after starting Vim in both cases?:
>
> :echo $HOME
> :echo $VIM
> :echo $VIMRUNTIME
> :echo &rtp

For Cygwin:

/home/michael
/usr/share/vim
/usr/share/vim/vim71
/home/michael/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim71,/usr/share/vim/vimfiles/after,/home/michael/.vim/after

And for Windows:

C:\Dokumente und Einstellungen\michael

C:\Programme\Vim
C:\Programme\Vim\vim72
C:/cygwin/home/michael/repos5ak/config/.vim,C:\Programme\Vim\vim72

> I expect it is some kind of configuration problem, as looking at Vim's
> source code, there is no reason I can see why the runtimepath order
> would go wrong.
>
> Your runtimepath is far from ideal, too. Something more like this
> would be better:
>
> let $HOME=C:/cygwin/home/michael/repos5ak/config
> set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after

Thanks for the suggestions. Trying to find a solution to this rtp
problem, I've stumbled upon this "after" directory feature, which is
documented under ":help after-directory".

> Most importantly, it keeps the after-directory in the list. The
> system-wide vimfiles is also included. Advice you get on this list, on
> the tips Wiki, in the help, etc. will assume you have a runtimepath
> much like this.

I'll add it to the list. My configuration likely is a bit dated. Haven't
RTFM with all the great updates and enhancements released since I've
started using Vim, only accidentally discovering new features. I'll do
better in the feature.

Of course, I can simply do the following:

M:\ :: md vimfiles
M:\ :: copy y:repos5ak\config\.vim\filetype.vim vimfiles
1 Datei(en) kopiert.

This works, of course. But I have this stupid obstination to find a
non-kludgy solution, and failing to do so myself, I came here.

Thanks,

Michael Ludwig

Ben Schmidt

unread,
Dec 14, 2008, 9:20:14 PM12/14/08
to vim...@googlegroups.com
> They're symlinked:

I had a bad feeling you'd say that. There goes the easy and obvious
solution!

> michael@wladimir:~ :-) ls -ld .vim*
> lrwxrwxrwx 1 michael Kein 11 Aug 11 2007 .vim -> config/.vim
> -rw------- 1 michael Kein 8324 Dec 14 21:42 .viminfo
> lrwxrwxrwx 1 michael Kein 13 Feb 22 2006 .vimrc -> config/.vimrc

I'm curious, though, what happened to the repos5ak path component? Is
~/config a symlink too or something?

> To Cygwin applications, these are symlinks. The Windows Vim, however,
> can't work with the shortcut file; it needs the real path, so that's
> what I feed it.

Yep, understood, and glad you've got that subtlety under control too.

>> Can you manually check the values of all the relevant options and
>> variables are as you expect after starting Vim in both cases?:
>>
>> :echo $HOME
>> :echo $VIM
>> :echo $VIMRUNTIME
>> :echo &rtp
>
> For Cygwin:
>
> /home/michael
> /usr/share/vim
> /usr/share/vim/vim71
> /home/michael/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim71,/usr/share/vim/vimfiles/after,/home/michael/.vim/after
>
> And for Windows:
>
> C:\Dokumente und Einstellungen\michael
> C:\Programme\Vim
> C:\Programme\Vim\vim72
> C:/cygwin/home/michael/repos5ak/config/.vim,C:\Programme\Vim\vim72

Yep. Well that's all as we expect, too.

> Of course, I can simply do the following:
>
> M:\ :: md vimfiles
> M:\ :: copy y:repos5ak\config\.vim\filetype.vim vimfiles
> 1 Datei(en) kopiert.
>
> This works, of course. But I have this stupid obstination to find a
> non-kludgy solution, and failing to do so myself, I came here.

I have the same stubbornness. It *should* work, without kludges, and
therefore ease maintenance.

I'll try to fire up Windows a bit later and see if I can reproduce the
problem, and then I'll write back again with some more ideas.

Ben.

Michael Ludwig

unread,
Dec 15, 2008, 4:50:21 PM12/15/08
to vim...@googlegroups.com
Ben Schmidt schrieb am 15.12.2008 um 13:20:14 (+1100):
>
> > michael@wladimir:~ :-) ls -ld .vim*
> > lrwxrwxrwx 1 michael Kein 11 Aug 11 2007 .vim -> config/.vim
> > -rw------- 1 michael Kein 8324 Dec 14 21:42 .viminfo
> > lrwxrwxrwx 1 michael Kein 13 Feb 22 2006 .vimrc -> config/.vimrc
>
> I'm curious, though, what happened to the repos5ak path component? Is
> ~/config a symlink too or something?

Yes. (I maintain come config files, like the Vim files, but also notes
and scripts in Subversion. The working copy has been ~/repos5ak for a
while now. There are convenience symlinks like ~/comp and ~/config and
others pointing into ~/repos5ak. Then, next generation of symlinks
pointing to ~/config, as seen above. I find this setup convenient and
quick to deploy on multiple machines, and Subversion allows me to keep
track of local modifications, so I can eventually integrate improvements
or bugs I may have introduced on some machine in my repository on my
home machine.)

> > M:\ :: md vimfiles
> > M:\ :: copy y:repos5ak\config\.vim\filetype.vim vimfiles
> > 1 Datei(en) kopiert.
> >
> > This works, of course. But I have this stupid obstination to find a
> > non-kludgy solution, and failing to do so myself, I came here.
>
> I have the same stubbornness. It *should* work, without kludges, and
> therefore ease maintenance.

Exactly. Stubbornness goes a long way, the drawback being that many a
times, it's a long way to go.

> I'll try to fire up Windows a bit later and see if I can reproduce the
> problem, and then I'll write back again with some more ideas.

Hey, I'm not expecting that much! You've already provided valuable
feedback.

You know what? I've just taken a shot at reversing my setup: main
configuration in the Windows %UserProfile%, Cygwin ~/.vimrc just
pointing there. Like this:

C:\ :: type cygwin\home\michael\.vimrc
source /cygdrive/c/Dokumente\ und\ Einstellungen/michael/_vimrc

And then I have %UserProfile%\_vimrc and %UserProfile%\vimfiles, the
_vimrc now featuring:

if has("unix")
set runtimepath=C:/DOKUME~1/michael/vimfiles,$VIMRUNTIME
endif

Guess what? Same story! Here's the output of ":script" from Cygwin:

1: /home/michael/.vimrc
2: /cygdrive/c/Dokumente und Einstellungen/michael/_vimrc
3: /usr/share/vim/vim71/syntax/syntax.vim
4: /usr/share/vim/vim71/syntax/synload.vim
5: /usr/share/vim/vim71/syntax/syncolor.vim
6: /usr/share/vim/vim71/filetype.vim
7: /cygdrive/c/DOKUME~1/michael/vimfiles/filetype.vim
[...]

More and more ready to try stuff bordering on superstition, I tried to
invert the setting of the runtimepath so that it should *not* work
(thinking that then, it maybe would):

if has("unix")
set runtimepath=$VIMRUNTIME,C:/DOKUME~1/michael/vimfiles
endif

But to no avail, unfortunately.

Michael Ludwig

Reply all
Reply to author
Forward
0 new messages