Prefix for an object member during initialization (e.g. on new())
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2Prefix for an object member during initialization (e.g. on new()).
Prepared example.vim
- Status
not sourced
Vim messages
Empty
Command entered · ready to apply
Prepared example.vim
- Status
not sourced
Vim messages
Empty
In the Vim9 constructor argument, this.lnum assigns the supplied 7 to the object's lnum member; :this is not a standalone command here.
Prepared example.vim
- Status
sourced- pos.lnum
7; constructor assigned object member
Vim messages
7
Before & after
Before
Prepared example.vim
- Status
not sourced
Vim messages
Empty
After
Prepared example.vim
- Status
sourced- pos.lnum
7; constructor assigned object member
Vim messages
7
Subject: :this. Documentation-backed illustration; assumes Vim9 class support; current unmodified buffer is saved as example.vim; not replay-verified. In the Vim9 constructor argument, this.lnum assigns the supplied 7 to the object's lnum member; :this is not a standalone command here.
vim9script
class Position
var lnum: number
def new(this.lnum)
enddef
endclass
var pos = Position.new(7)
echo pos.lnumCursor on line 1, column 1Details & Vim help
Prefix for an object member during initialization (e.g. on new()). Supply this.member as part of a complete Vim9 constructor declaration. The index label :this names a prefix and has no standalone Ex invocation. 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.