Create a variable as a constant
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2Create a variable as a constant.
Script runtime
- Load state
not sourced
Command entered · ready to apply
Script runtime
- Load state
not sourced
Command line
- Typed text
:source const-demo.vim- Insertion offset
22
:const appears in the complete source file. The legacy const declaration initializes and locks g:limit.
Script runtime
- g:limit
3 (locked)- echo output
3
Before & after
Before
Script runtime
- Load state
not sourced
After
Script runtime
- g:limit
3 (locked)- echo output
3
Documentation-backed illustration. legacy :const support and +eval; g:limit is not already defined; source code is prepared as const-demo.vim. :const appears in the complete source file. The legacy const declaration initializes and locks g:limit. Primary help: :const.
const g:limit = 3
echo g:limitCursor on line 1, column 1Details & Vim help
Create a variable as a constant. 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 :cons[t] 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.