Take the 2-minute tour ×

Let's say I have a tarball of all my vim config - everything normally inside ~/.vim (plugins, autoload, colours, all that stuff), and a vimrc file. I extract this to a directory somewhere. So in the directory where I am ($PWD), there is a "vim" folder and a "vimrc" file. (note: this directory will be read-only, so vim shouldn't try to write into it).

What command-line arguments or environment variables can I give to vim to ensure that all my plugins, syntax, etc is loaded as well as the vimrc, in the same order as they normally would if they were located in ~/.vim and ~/.vimrc

As a bonus, I'd like to ignore the host computer's ~/.vimrc and ~/.vim if possible (but this is not mandatory).

If you're wondering why I don't just chuck the files in ~/.vimrc and ~/,vim, I'm trying to package up my own vim configuration and take it with me. I don't want to clobber the vim config of the computer I'm using, I just want to start a vim session with my config.

share|improve this question
I have used the following in the past, but autoload functions don't seem to work (when they are called from my vimrc): vim --cmd "set runtimepath+=$(dirname $0)/vim,$VIMRUNTIME" -u "$(dirname $0)"/vimrc "$@" –  gfxmonk Jul 31 '10 at 8:15

4 Answers 4

up vote 20 down vote accepted

I have a portable .vim folder exactly as you described, this is how I have set it up:

  • Put your portable .vimrc file inside your .vim folder.

  • Add the following lines to the start of your portable .vim/.vimrc:

" set default 'runtimepath' (without ~/.vim folders)
let &runtimepath = printf('%s/vimfiles,%s,%s/vimfiles/after', $VIM, $VIMRUNTIME, $VIM)

" what is the name of the directory containing this file?
let s:portable = expand('<sfile>:p:h')

" add the directory to 'runtimepath'
let &runtimepath = printf('%s,%s,%s/after', s:portable, &runtimepath, s:portable)
  • Start vim by using: vim -u /path/to/portable/vim/.vimrc.
share|improve this answer
There seems to be a <sfile> missing in expand. I think it should be let s:portable = expand('<sfile>:p:h'). It only worked like this for me. Vim 7.3 –  RedX Mar 1 '12 at 15:09
set nocompatible should be the first line. It seems -u disables it as default. –  Paolo.Bolzoni Aug 6 at 14:09

On Unix & Linux systems (and maybe Windows) Vim uses the $HOME environment variable to locate the .vimrc file and .vim directory. So you can cd into the directory where you have your custom versions and start vim or gvim like this:

HOME=. vim files....
share|improve this answer
good idea, but there are a couple of problems: (1) this breaks opening up files using ~ (like :e ~/Docs/whatever.txt). (2) I forgot to mention this, but the working directory has to be readonly (I'll update the question). vim complains when it can't write to ~/.viminfo, etc –  gfxmonk Aug 1 '10 at 3:24
This solved my problem of running different versions of vim from different directories and with different vimrc files. Thanks! –  tandrewnichols Jan 23 at 18:09

This "vimrc File and Vim Runtime Directories" screencast might be useful, as well as the vim documentation for 'runtimepath', which states the following:

This is a list of directories which will be searched for runtime files:
      filetype.vim  filetypes by file name |new-filetype|
      scripts.vim   filetypes by file contents |new-filetype-scripts|
      autoload/ automatically loaded scripts |autoload-functions|
      colors/   color scheme files |:colorscheme|
      compiler/ compiler files |:compiler|
      doc/      documentation |write-local-help|
      ftplugin/ filetype plugins |write-filetype-plugin|
      indent/   indent scripts |indent-expression|
      keymap/   key mapping files |mbyte-keymap|
      lang/     menu translations |:menutrans|
      menu.vim  GUI menus |menu.vim|
      plugin/   plugin scripts |write-plugin|
      print/    files for printing |postscript-print-encoding|
      spell/    spell checking files |spell|
      syntax/   syntax files |mysyntaxfile|
      tutor/    files for vimtutor |tutor|

    And any other file searched for with the |:runtime| command.

    The defaults for most systems are setup to search five locations:
    1. In your home directory, for your personal preferences.
    2. In a system-wide Vim directory, for preferences from the system
    3. In $VIMRUNTIME, for files distributed with Vim.

    4. In the "after" directory in the system-wide Vim directory.  This is
       for the system administrator to overrule or add to the distributed
       defaults (rarely needed)
    5. In the "after" directory in your home directory.  This is for
       personal preferences to overrule or add to the distributed defaults
       or system-wide settings (rarely needed).
share|improve this answer
thanks. I actually had tried setting runtimepath, but it didn't seem to work for loading pathogen functions (it lives in autoload, which I thought was causing trouble). It turns out it was just bailing out for other reasons (cp mode was on). My final script sets $VIM_BASE, and my skelton vimrc adds $VIM_BASE to runtimepath and then sources the real vimrc. –  gfxmonk Aug 1 '10 at 4:31

My solution isn't quite the same but could be adapted pretty easily.

I have my Vim setup on my workstation and it's shared through regular Windows file sharing. I have this batch file that I can launch from any other computer in the building (and there's an install of Vim on another network share since most workstations don't even have Vim installed). I just run this batch file and am in my happy place.

set MYWORK=\\my_pc\work
set RCBASE=%MYWORK%\personal\utilities\tom.

start \\server\software\vim\vim73\gvim.exe -u %RCBASE%vimrc -U %RCBASE%gvimrc

So basically the adaptation would put the batch file, shell script, or otherwise into the archive you're unpacking and launch the system vim with your local files.

share|improve this answer

Your Answer


