Take the 2-minute tour ×

Over the last couple of months, I've built a series of files full of vim-commands to auto-generate boilerplate code for my projects. It's allowed me to work faster.

However, the only way I know how to run these scripts is by assigning them to key-combinations in ~/.vimrc. There's only so many keys I can remap.

Is there a way to run these scripts from the : commandline with a few keystrokes?

For example, I have a unit_test_cpp.vim script, which builds a boilerplate unit test cpp file. I'd like to be able to type


or some other simple combination of letters with a simple mnemonic to run this script on my currently open file.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

You could use the command feature of vim. In your unit_test_cpp.vim file you would add something like this:

command Utc call CreateUnitTests()

Now when you type :Utc it will call your function. The only limitation is that your command must start with an uppercase letter.

share|improve this answer

Open Vim and enter the following:

:source /path/to/vim/file/name.vim
share|improve this answer

Script or function? If it is a function, try

:call FunctionName() 
share|improve this answer
They are files with vim commands. I can run them with the so command. –  J. Polfer Jul 30 '10 at 19:24
Each of the so commands is wrapped by a function in .vimrc. So could I use the :call FunctionName() method to run those functions from .vimrc? –  J. Polfer Jul 30 '10 at 19:25
basically. if you had function! Foo() source 'foo.vim' endfunction you could could :call Foo() and it should source foo.vim, or you can map the command as rq suggests below to avoid the :call... –  Doon Jul 30 '10 at 20:31

Your Answer


