Vim Recall繁體中文

Create a variable as a constant

:const

Example

Normal 0 / 2

Create a variable as a constant.

Script runtime

Load state
not sourced
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.

Sample buffer
const g:limit = 3
echo g:limit
Cursor on line 1, column 1
Details & 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.