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

ID : 45460

viewed : 61

Tags : pluginsvivimplugins





Top 5 Answer for plugins - How do I "source" something in my .vimrc file?

vote vote

100

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 
vote vote

85

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

vote vote

73

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.

vote vote

70

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) 
vote vote

54

Top 3 video Explaining plugins - How do I "source" something in my .vimrc file?







Related QUESTION?