Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto change location of .vimrc and .vim

Tags:

vim

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.

like image 293
crs Avatar asked Jun 03 '13 19:06

crs


People also ask

Where is .vimrc located?

Vim's user-specific configuration file is located in the home directory: ~/. vimrc , and Vim files of current user are located inside ~/. vim/ . The global configuration file is located at /etc/vimrc .

Where should .vimrc be Windows?

RECOMMENDATION: Put all your Vim configuration stuff in the $HOME/. vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it easy to copy it to another system.

Where should we need to create .vimrc file?

All you have to do is to create a . vimrc file in the HOME directory of the user than you want to configure Vim for and add the required Vim configuration options there. For simplicity, I will refer to both system wide Vim configuration file and user specific Vim configuration file as vimrc file.

How do I change Vim default settings?

1. Enable the options for an individual file inside the Vim session using :set Open the desired file in Vim, type any option using the :set command in the Normal mode, and press Enter. 2. Enable the options permanently for all the files by specifying them in the local Vim configuration file ~/.


2 Answers

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.

like image 188
Ingo Karkat Avatar answered Nov 16 '22 04:11

Ingo Karkat


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.

like image 34
Simão Afonso Avatar answered Nov 16 '22 03:11

Simão Afonso