Vim Recall繁體中文

Variable declaration in Vim9

:var

Example

Normal 0 / 2

Variable declaration in Vim9.

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
count
5; script-local number

Vim messages

5

Subject: :var. Documentation-backed illustration; assumes Vim9 script support; current unmodified buffer is saved as example.vim; not replay-verified. var declares the script-local number count; incrementing it changes its value from 3 to 5.

Sample buffer
vim9script
var count: number = 3
count += 2
echo count
Cursor on line 1, column 1
Details & Vim help

Variable declaration in Vim9. 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. Availability and exact behavior can depend on Vim build features, options, mappings and editor state; the linked help is authoritative. Vim9 script constructs require the documented Vim9 script context.