Return from a user function
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2Return from a user function.
Prepared example.vim
- Status
not sourced
Vim messages
Empty
Command entered · ready to apply
Prepared example.vim
- Status
not sourced
Vim messages
Empty
In this legacy function, return 7 leaves Answer immediately. The following echo is skipped and the caller receives 7.
Prepared example.vim
- Status
sourced- Answer() result
7- Unreachable echo
not executed
Vim messages
7
Before & after
Before
Prepared example.vim
- Status
not sourced
Vim messages
Empty
After
Prepared example.vim
- Status
sourced- Answer() result
7- Unreachable echo
not executed
Vim messages
7
Subject: :return. Documentation-backed illustration; assumes +eval and legacy Vimscript context; current unmodified buffer is saved as example.vim; not replay-verified. In this legacy function, return 7 leaves Answer immediately. The following echo is skipped and the caller receives 7.
function! Answer()
return 7
echo 'unreachable'
endfunction
echo Answer()Cursor on line 1, column 1Details & Vim help
Return from a user function. This Ex reference uses the full command name; the alphabetical index omits arguments. Supply the ranges, arguments, flags and prerequisite state documented in the linked help. Press Enter to submit a complete command. The index spelling :retu[rn] puts the optional abbreviation suffix in square brackets; those brackets are not typed. Availability and exact behavior can depend on Vim build features, options, mappings and editor state; the linked help is authoritative.