Wednesday, October 26, 2011

Re: Please fix: make Windows Vim use same files as unix. No reason not to and it's confusing in mixed envirionments.

Hi,

I use the following setup which works fine between Win7 and Linux. I
suppose it should work on other systems, too.

The Vim files are in the directory ~/myvimfiles. This directory is
copied between different systems. Vim settings are in the following
files:
~/myvimfiles/vimrc
~/myvimfiles/gvimrc

There are no dots nor underscores in the filenames. This makes the
files usable on any system.

To load the config files I have these files in ~/:

" file: ~/.vimrc or $HOME/_vimrc
exec 'source ' . resolve(expand("<sfile>:p:h")) . '/myvimfiles/
vimrc'

" file: ~/.gvimrc or $HOME/_gvimrc
exec 'source ' . resolve(expand("<sfile>:p:h")) . '/myvimfiles/
gvimrc'

The runtimepath is modified in myfiles/vimrc like this:

let s:thisfile = resolve(expand('<sfile>'))
let $MYVIMDIR = fnamemodify(s:thisfile, ':p:h')
let s:paths = split(&rtp, ',')
let i = index(s:paths, $MYVIMDIR)
if i < 0
call insert(s:paths, $MYVIMDIR, 0)
let &rtp = join(s:paths, ',')
endif

This sets the RTP correctly when the contents of ~/.vimrc is set as
above and also when it is a symlink to ~/myvimfiles/vimrc.

For machine-dependent settings (eg. the root directories of projects,
notes, etc.) I use hostname() to load those settings. Note that this
might not work if the string returned by hostname contains characters
that are not valid in filenames:

let s:configdir=$MYVIMDIR . '/config'
let s:hostfile = s:configdir . '/hostrc/' . hostname() . '.vim'
if filereadable(s:hostfile)
exec 'source ' . s:hostfile
endif

The variable $MYVIMDIR is also used to manage plugins in a pathogen-
like environment: the plugins are downloaded to the directory
s:bundledir = $MYVIMDIR . '/bundles'.

Marko

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: