Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override ~/.vim and ~/.vimrc paths (but no others) in vim?

Tags:

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.

like image 706
gfxmonk Avatar asked Jul 31 '10 07:07

gfxmonk


People also ask

How do you overwrite in Vim?

Replace mode allows you replace existing text by directly typing over it. Before entering this mode, get into normal mode and put your cursor on top of the first character that you want to replace. Then press 'R' (capital R) to enter replace mode. Now whatever you type will replace the existing text.

Where does Vim look for vimrc?

vimrc , and Vim files of current user are located inside ~/. vim/ . The global configuration file is located at /etc/vimrc .

Where is vimrc stored?

The system vimrc should normally be left unmodified and is located in the $VIM * directory.


2 Answers

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.
like image 122
too much php Avatar answered Oct 09 '22 02:10

too much php


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.... 
like image 34
Dave Kirby Avatar answered Oct 09 '22 01:10

Dave Kirby