views:

1987

answers:

4

I've been working on expanding my vim-foo lately and I've run across a couple of plugins (autotag.vim for example) that require them to be "sourced" in my .vimrc file. What exactly does this mean and how do I do it?

+8  A: 

Files in your .vim/plugin directory are sourced (loaded) automatically.

Michiel de Mare
+5  A: 

There is always the :source file command. I usually write .vimrc that contains custom commands and what not for the console application and then a .gvimrc that contains additional goodies that are appropriate for a windowed version. My .gvimrc starts with source $HOME/.vimrc to pick up everything from the console version before adding in new stuff.

D.Shawley
+2  A: 

There are normally two vimrc files, one is _vimrc and the other _gvimrc (in the first one are the things for vim, and in the second for gvim - graphical things) - although most people I know just put everything in _vimrc.

A good practice is to keep all your extra files (plugins, colorschemes, snippets ...) in a separate (your own) vimfiles directory (which you can take with you).

If you do

:help vimfiles

vim will tell your vimfiles directory should be located. It depends somewhat on the platform (win, unix). On windows the usual is in your user folder (documents and settings, then user ...). In vimfiles directory there are a couple of subdirectories. Amongst them is the "plugin" subdirectory. Plugins put in that dir will be loaded automatically (also plugins put in subdirectories of "plugin"). If you do not wish to load it automatically, just put it in your "vimfiles", or some other directory, and

:so plugin_name.vim (with the appropriate path)
(you can use the $vim, $vimfiles, and $home as shortcuts when defining path to plugin)
ldigas
+5  A: 

Sourcing a file is 'executing' it. Essentially, each line of the file is considered a command. Sourcing it is the same as typing each command in order. You source with the command :source(usually shortened to :so)

So if you source myStuff.vim

:so myStuff.vim

and if myStuff.vim contained these lines

set xx iI just intersted this<C-]>
set yy bbbb4dw

Its the same as if you typed those commands into vim

:set xx iI just intersted this<C-]>
:set yy bbbb4dw

The only file sourced by default is the .vimrc(_vimrc on windows) so that's a place you can keep all the commands you use to set up vim every time.

Where it gets interesting is the fact that since a sourced file is just a series of commands, and sourcing is a command, you can source files from your source files. So pluggins you use every time could be sourced when you start up vim by adding a line to your .vimrc like this

 so myPluggin.vim
Whaledawg