# 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

```
     if a Vimscript function doesn't return a value, it implicitly returns 0. 
```

Now check this case

```
:function TextwidthIsTooWide()

:  if &l:textwidth ># 80

:    return 1

:  endif

:endfunction
```

Test case1

```
:set textwidth=80
:if TextwidthIsTooWide()
:  echom "WARNING: Wide text!"
:endif
```

output: (function return 0)

Test case2

```
:setlocal textwidth=100
:if TextwidthIsTooWide()
:  echom "WARNING: Wide text!"
:endif
```

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fashaun.gitbook.io/dev-vim/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
