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

Functions, Types, and Variables

Vim includes many built-in functions that we can call in our own code—everything from sort and search to browse and winheight. We can also write our own functions, using function and endfunction, but our functions have to begin with uppercase letters in order to distinguish them from built-in functions. Here’s an example that uses the command :echo to output a message to the user:

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

To call this function, we need to save this code in a file, so let’s do that first. Then we need to tell Vim to load, or source, that file. We do this by calling the :source command on the Vim command line, like this:

 
:​ ...

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