Declare an immutable variable in Vim9
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2Declare an immutable variable in Vim9.
Script runtime
- Load state
not sourced
Command entered · ready to apply
Script runtime
- Load state
not sourced
Command line
- Typed text
:source final-demo.vim- Insertion offset
22
:final appears in the complete source file. final prevents rebinding nums while permitting this list-item change.
Script runtime
- nums binding
final; cannot be rebound- nums contents
[9, 2]- echo output
[9, 2]
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.
vim9script
final nums = [1, 2]
nums[0] = 9
echo numsCursor on line 1, column 1Details & 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.