Vim Recall繁體中文

Declare an immutable variable in Vim9

:final

Example

Normal 0 / 2

Declare an immutable variable in Vim9.

Script runtime

Load state
not sourced
Before & after

Before

Script runtime

Load state
not sourced

After

Script runtime

nums binding
final; cannot be rebound
nums contents
[9, 2]
echo output
[9, 2]

Documentation-backed illustration. Vim9 script support; source code is prepared as final-demo.vim. :final appears in the complete source file. final prevents rebinding nums while permitting this list-item change. Primary help: :final.

Sample buffer
vim9script
final nums = [1, 2]
nums[0] = 9
echo nums
Cursor on line 1, column 1
Details & Vim help

Declare an immutable variable 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.