But First, a Function

At the end of The Structure of a Vim Plugin, we created our main plugin directory, mpc. This is where we’ll be putting the different directories in which Vim looks for VimL source files.

Under mpc, create the plugin directory and then create a file under it called mpc.vim. It should look like this:

plugin/mpc/plugin/mpc.vim
 
function​! OpenMPC()
 
let​ cmd = ​"mpc --format '%title% (%artist%)' current"
 
echomsg​ system(cmd)[:-2]
 
endfunction

Because we appended the plugin directory to our runtimepath, Vim will load it automatically the next time we start it up. For now, though, save the file and then source it:

 
:​source​ %

Now Vim should have OpenMPC ready to go. Make sure that mpc is running and then, from ...

Get The VimL Primer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.