Vim Recall繁體中文

Return from a user function

:return

Example

Normal 0 / 2

Return from a user function.

Prepared example.vim

Status
not sourced

Vim messages

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

Sample buffer
function! Answer()
  return 7
  echo 'unreachable'
endfunction
echo Answer()
Cursor on line 1, column 1
Details & 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.