O'Reilly logo

The VimL Primer by Benjamin Klein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing User Commands

At this point you probably won’t be shocked to learn how we define our own commands: by using a command! Specifically, we use :command to define commands. (Hmm—that certainly sounds redundant.)

User commands, like user functions, have to start with uppercase letters. And what’s funny about user commands is that their job is simply to call built-in commands. If we want to define a command that calls a function—as we will be doing—we execute the :call command. Consider an example:

mappings/command.vim
 
function​! EchoQuote()
 
echo ​'A poet can but ill spare time for prose.'
 
endfunction
 
command​ Quote ​call​ EchoQuote()

This defines a user command called :Quote. Just like with :command itself, we can leave the colon ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required