Functions
Vimscript functions must start with a capital letter if they are unscoped! (Function name must start with a capital or contain a colon:)
Function define
:function CallSean()
: echom "Hi sean"
:endfunction
call CallSean()
output: "Hi sean"
:function GetSean()
: return "Basket"
:endfunction
call GetSean()
output : nothing
echom GetSean()
output : Basket
Implicit Returning
echom CallSean()
output: "Hi sean" 0
Now check this case
Test case1
output: (function return 0)
Test case2
output: "WARNING: Wide text!" (function return 1)
Exercises
Read :help :call. Ignore anything about "ranges" for now. How many arguments can you pass to a function? Is this surprising?
Read the first paragraph of :help E124 and find out what characters you're allowed to use in function names. Are underscores okay? Dashes? Accented characters? Unicode characters? If it's not clear from the documentation just try them out and see.
Read :help return. What's the "short form" of that command (which I told you to never use)? Is it what you expected? If not, why not?
Function Arguments
:help internal-variables
Last updated
Was this helpful?