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:
| : ... |
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.