11

How can I change the location of the .vim folder and the .vimrc file so that I can use two (or more) independent versions of vim? Is there a way to configure that while compiling vim from source? (maybe an entry in the feature.h?)

Why do I want to do such a thing?: I have to work on project that use python2 as well as python3, therefore I want to have two independent vim setups with different plugins, configurations etc. Moreover, one version has to be compiled with +python, the other with +python3.

crs
  • 501
  • 1
  • 4
  • 12
  • If you're going to install another version if Vim use altinstall to /usr/local/bin. You can also define another `.vimrc` using `$ vim -u path/to/.vimrc`. Not sure what you would do with the `.vim` directory or `.viminfo` though. – timss Jun 03 '13 at 19:05
  • Well, I've forgotten to mention that i figured out how to start vim with another .vimrc using the '-u' command. But thats doesn't affect the .vim folder. Changing the vim runtimepath withing a new .vimrc doesn't work, because if you try to load plugins you'll get an error. – crs Jun 03 '13 at 19:09
  • You can have both `+python` *and* `+python3`. – romainl Jun 03 '13 at 19:25
  • compiling vim with support for both, python2 and 3, is not the problem. It's rather a pain if you want to use different plugins for each python version. – crs Jun 03 '13 at 21:44

4 Answers4

10

You can influence which ~/.vimrc is used via the -u vimrc-file command-line argument. Since this is the first initialization, you can then influence from where plugins are loaded (i.e. the .vim location) by modifying 'runtimepath' in there.

Note that for editing Python files of different versions, those settings (like indent, completion sources, etc.) are taken from filetype plugins which are sourced for every buffer separately, so it should be possible to even edit both Python 2 and 3 in the same Vim instance. (Unless you have some badly written plugins that define global stuff.) So for that, some sort of per-buffer configuration (some :autocmds on the project path, or some more elaborate solution (search for localrc plugins or questions about project vimrc here) might suffice already.

Also note that when the Python interpreter (which you'd only need for Python-based plugins and some interactive :py commands, not for editing Python) is compiled in with dynamic linking (which is the default at least on Windows), you can have both Python 2 and 3 support in the same Vim binary.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 1
    If you modify the 'runtimepath' you get some weird error msgs like: Error detected while processing /home/user/vimp2/vimrc: line 4: E117: Unknown function: pathogen#infect therefore i'd like to have to totally independent versions of vim with seperate configfiles and -folders. – crs Jun 03 '13 at 21:35
  • 2
    Put `set runtimepath` (no options) as the second line in your (working) .vimrc file. Restart vim, it will display something like `runtimepath=~/.vim,/opt/local/share/vim/vimfiles,/opt/local/share/vim/vim74,/opt/local/share/vim/vimfiles/after,~/.vim/after`. Use that as your new runtimepath, and you'll have no issues. – Orwellophile Sep 13 '15 at 14:02
4

I think the easiest solution would be just to let pathogen handle your runtimepath for you.

pathogen#infect() can take paths that specify different directories that you can use for your bundle directory.

So if your .vim directory would look like this

.vim/
    autoload/
        pathogen.vim
    bundle_python2/
        <plugins>
    bundle_python3/
        <other plugins>

Then inside one of your vimrc for python 2 specific stuff you would have

call pathogen#infect('bundle_python2/{}')

and for python 3 specific stuff you would have

call pathogen#infect('bundle_python3/{}')

Since each plugin folder is really just a .vim folder you can place your python specific configuration stuff in a folder of the corresponding bundle and pretend its a .vim.

This structure also has the added benefit that you can change both configurations at the same time if you feel like it by putting common stuff in .vim normally.

You can also pass multiple bundle directories if you feel like to pathogen so you can have plugins that are shared without duplicating files. You just do this by passing multiple paths to pathogen#infect('bundle/{}', 'bundle_python3/{}')

After this is all done you can just create aliases for vim to call the correct vimrc file.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
2

I found a way to do this! You can just create a fake $HOME, whose contents are simply the .vim folder and .vimrc. Then, when running vim, set the HOME environment variable to that folder, and change it back on VimEnter.

Run vim with:

OLD_HOME="$HOME" HOME="$FAKE_HOME" vim

Add this to your .vimrc:

autocmd VimEnter * let $HOME = $OLD_HOME

On Windows you can use

let $HOME = $HOMEDRIVE.$HOMEPATH

insetead, no need to store the old home.

This works, but if you use $HOME inside your vimrc or any plugins will see the old value, it might affect them somehow. So far I haven't seen it.

  • 2
    This is a total hack and a really bad idea - so prone to break hard in mysterious ways, long after you've forgotten that you're spoofing `$HOME`. – OJFord Oct 08 '16 at 21:14
1

Note: I don't really recommend doing this.

If you really really want to recompile vim so that it uses a different vimrc and different configuration directory take a look at src/feature.h

Search this file for USR_VIMRC_FILE. Uncomment it and place the name of your vimrc here. This will change the defualt vimrc file.

So it should look something like this

#define USR_VIMRC_FILE "~/path/to/vimrc"

Inside src/os_unix.h or src/os_mac.h and search for DFLT_RUNTIMEPATH. Change all instance of ~/.vim to whatever folder you want. This should set the default runtime path that vim searches for settings.

FDinoff
  • 30,689
  • 5
  • 75
  • 96