I want to have something like a virtualenv for Vim: on my Windows machine, the plugins are normally located in vimfiles, _vimrc holds the settings.

For debugging reasons, I want to create a separate environment with an empty vimfiles2 directory and a blank _vimrc2 file.

How do I do that?

2 Answers 2


An easier way to do this than overriding the 'runtimepath' setting in your vimrc is to set the HOME environment variable for the vim command in your shell command. e.g.

In bash:

mkdir ~/new-vimhome
HOME=~/new-vimhome vim

Or in the Windows Command prompt:

mkdir %USERDRIVE%%USERPATH%\new-vimhome
set HOME=%USERDRIVE%%USERPATH%\new-vimhome

(Note that Windows Vim uses the HOME environment variable if it is set, but it usually isn't — and other programs won't generally check it — so it should be safe to set it persistently as we do above.)

You can then set up any Vim configuration you desire within that home directory, in the usual way. e.g.:


mkdir ~/new-vimhome/.vim
touch ~/new-vimhome/.vimrc

Windows Command Prompt:

mkdir %USERDRIVE%%USERPATH%\new-vimhome\vimfiles
vim %USERDRIVE%%USERPATH%\new-vimhome\_vimrc

N.B. As @eckes notes in a comment, this solution does have the caveat that $HOME will point to the new directory rather than your real home directory, so the $HOME environment variable and ~ shortcut can't be used for accessing files located there within an instance Vim running in this way. (Although you can of course still access such files using absolute paths or Windows's standard environment variables.) If you don't want this degree of separation from your usual environment, their solution might therefore be preferable.

  • Well but this would produce a new HOME dir where only Vim lives. Access from Vim to other files in my real HOME would be cumbersome then, won't it?
    – eckes
    Jan 19, 2018 at 10:46
  • @eckes I guess so! I'll add that as a note.
    – Rich
    Jan 19, 2018 at 10:56

Just found it myself: the runtimepath is the solution!

  1. create a new vimrc, e.g. new-vimrc
  2. inside that new-vimrc set up the runtimepath so that it points to a new directory. Sample for Windows:

    set runtimepath=~/new-vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after
  3. Start your Vim now with the -u option specifying the location of the new vimrc to use:

    vim -u $HOME/new-vimrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.