January 2015
Beginner to intermediate
85 pages
1h 58m
English
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:
| | : ... |
Read now
Unlock full access