nerez
nerez

Reputation: 447

How to add a vimrc path to vim

currently there are a few paths where .vimrc files are being searched. (as can be seen in :scriptnames command).

How do I add another path?

Upvotes: 2

Views: 4558

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172570

The 'runtimepath' option specifies the locations of the Vim configuration subdirectories (i.e. directories containing autoload/, plugin/, syntax/, etc.) The Pathogen plugin made it popular to extend this so that each plugin is installed into a separate such subdirectory, and other plugin managers (like Vundle) do that as well.

Now, there's only one .vimrc (and you can change its location via the -u command-line argument), but nothing prevents you from using :source path/to/another/script.vim to load other Vim scripts during startup.

TL;DR

To execute a separate Vimscript file during startup, just :source it from your ~/.vimrc. If you have a plugin(s) that you want to install in a separate location, use :set runtimepath+=path/to/pluginroot in your ~/.vimrc, or just use Pathogen or another plugin manager.

Upvotes: 1

Luc Hermitte
Luc Hermitte

Reputation: 32936

You're mistaken. :scriptnames tells you which scripts were loaded. It will be:

  • .vimrc,
  • possibly .gvimrc,
  • plus all plugins in 'runtimepath',
  • plus all ftplugins, syntax files and indent files in runtimepath that apply for all the buffers you have edited,
  • plus the autoload plugins loaded by the previous files,
  • plus the files you've sourced manually.

If you want to change the places where to search for your .vimrc, it will be more complex as vim has a very specific heuristic to search for a .vimrc. See :h startup.


Any way. If you really want to add a path where the .vimrc file will be searched, it's not possible unless you define an alias to vim that use the -u flags.

If you want to add other paths where to look for plugins, you'll have to set the 'runtimepath' option in your .vimrc. For instance, :set rtp+=~/.vim/addon/foobar will have all plugins named $HOME/.vim/addon/foo/plugin/*.vim and $HOME/.vim/addon/foo/after/plugin/*.vim loaded automatically, plus the ftplugin/syntax file/indent files loaded automatically as well if you enable them, and when you enter a buffer related to them.

Upvotes: 2

Related Questions