Vim Recall繁體中文

Vim9: export an item from a script

:export

Example

Normal 0 / 2

Vim9: export an item from a script.

Script runtime

Load state
not sourced

Prepared module: limits.vim

vim9script
export const LIMIT = 3
Before & after

Before

Script runtime

Load state
not sourced

Prepared module: limits.vim

vim9script
export const LIMIT = 3

After

Script runtime

Imported namespace
limits
limits.LIMIT
3
echo output
3

Prepared module: limits.vim

vim9script
export const LIMIT = 3

Documentation-backed illustration. Vim9 script modules; Vim's current directory contains the prepared limits.vim and consumer.vim; source code is prepared as consumer.vim. :export appears in the complete source file. limits.vim exports LIMIT; consumer.vim imports the module and prints limits.LIMIT. Primary help: :export.

Sample buffer
vim9script
import './limits.vim' as limits
echo limits.LIMIT
Cursor on line 1, column 1
Details & Vim help

Vim9: export an item from a script. 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.