How do I "source" something in my .vimrc file?

Paul Wicks picture Paul Wicks · Apr 29, 2009 · Viewed 83.9k times · Source

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?

Answer

Whaledawg picture Whaledawg · Apr 30, 2009

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

It's 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 plugins you use every time could be sourced when you start up Vim by adding a line to your .vimrc like this

 so myPlugin.vim