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

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


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.


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

Tags:

Plugins

Vi

Vim