1- *if_lua.txt* For Vim version 9.1. Last change: 2021 Aug 06
1+ *if_lua.txt* For Vim version 9.1. Last change: 2025 Oct 12
22
33
44 VIM REFERENCE MANUAL by Luis Carvalho
@@ -71,7 +71,7 @@ If you use LuaJIT you can also use this: >
7171 argument being set to the text of each line in turn,
7272 without a trailing <EOL> , and the current line number.
7373 If the value returned by the function is a string it
74- becomes the text of the line in the current turn. The
74+ becomes the text of the line in the current turn. The
7575 default for [range] is the whole file: "1,$".
7676
7777Examples:
@@ -96,44 +96,44 @@ Examples:
9696<
9797
9898All these commands execute a Lua chunk from either the command line (:lua and
99- :luado) or a file (:luafile) with the given line [range] . Similarly to the Lua
100- interpreter, each chunk has its own scope and so only global variables are
101- shared between command calls. All Lua default libraries are available. In
99+ :luado) or a file (:luafile) with the given line [range] . Similarly to the
100+ Lua interpreter, each chunk has its own scope and so only global variables are
101+ shared between command calls. All Lua default libraries are available. In
102102addition, Lua "print" function has its output redirected to the Vim message
103103area, with arguments separated by a white space instead of a tab.
104104
105105Lua uses the "vim" module (see | lua-vim | ) to issue commands to Vim
106- and manage buffers (| lua-buffer | ) and windows (| lua-window | ). However,
106+ and manage buffers (| lua-buffer | ) and windows (| lua-window | ). However,
107107procedures that alter buffer content, open new buffers, and change cursor
108108position are restricted when the command is executed in the | sandbox | .
109109
110110
111111==============================================================================
1121122. The vim module *lua-vim*
113113
114- Lua interfaces Vim through the "vim" module. The first and last line of the
115- input range are stored in "vim.firstline" and "vim.lastline" respectively. The
116- module also includes routines for buffer, window, and current line queries,
117- Vim evaluation and command execution, and others.
114+ Lua interfaces Vim through the "vim" module. The first and last line of the
115+ input range are stored in "vim.firstline" and "vim.lastline" respectively.
116+ The module also includes routines for buffer, window, and current line
117+ queries, Vim evaluation and command execution, and others.
118118
119119 vim.list([arg] ) Returns an empty list or, if "arg" is a Lua
120120 table with numeric keys 1, ..., n (a
121121 "sequence"), returns a list l such that l[i] =
122122 arg[i] for i = 1, ..., n (see | List | ).
123123 Non-numeric keys are not used to initialize
124- the list. See also | lua-eval | for conversion
125- rules. Example: >
124+ the list. See also | lua-eval | for conversion
125+ rules. Example: >
126126 :lua t = {math.pi, false, say = 'hi'}
127127 :echo luaeval('vim.list(t)')
128128 :" [3.141593, v:false], 'say' is ignored
129129<
130130 vim.dict([arg] ) Returns an empty dictionary or, if "arg" is a
131131 Lua table, returns a dict d such that d[k] =
132132 arg[k] for all string keys k in "arg" (see
133- | Dictionary | ). Number keys are converted to
134- strings. Keys that are not strings are not
135- used to initialize the dictionary. See also
136- | lua-eval | for conversion rules. Example: >
133+ | Dictionary | ). Number keys are converted to
134+ strings. Keys that are not strings are not
135+ used to initialize the dictionary. See also
136+ | lua-eval | for conversion rules. Example: >
137137 :lua t = {math.pi, false, say = 'hi'}
138138 :echo luaeval('vim.dict(t)')
139139 :" {'1': 3.141593, '2': v:false,
@@ -148,29 +148,29 @@ Vim evaluation and command execution, and others.
148148 :" 0z31326162.0080FEFF
149149<
150150 vim.funcref({name} ) Returns a Funcref to function {name} (see
151- | Funcref | ). It is equivalent to Vim's
151+ | Funcref | ). It is equivalent to Vim's
152152 function().
153153
154154 vim.buffer([arg] ) If "arg" is a number, returns buffer with
155155 number "arg" in the buffer list or, if "arg"
156- is a string, returns buffer whose full or short
157- name is "arg". In both cases, returns 'nil'
158- (nil value, not string) if the buffer is not
159- found. Otherwise, if "toboolean(arg)" is
156+ is a string, returns buffer whose full or
157+ short name is "arg". In both cases, returns
158+ 'nil' (nil value, not string) if the buffer is
159+ not found. Otherwise, if "toboolean(arg)" is
160160 'true' returns the first buffer in the buffer
161161 list or else the current buffer.
162162
163163 vim.window([arg] ) If "arg" is a number, returns window with
164164 number "arg" or 'nil' (nil value, not string)
165- if not found. Otherwise, if "toboolean(arg)"
165+ if not found. Otherwise, if "toboolean(arg)"
166166 is 'true' returns the first window or else the
167167 current window.
168168
169- vim.type({arg} ) Returns the type of {arg} . It is equivalent to
170- Lua's "type" function, but returns "list",
169+ vim.type({arg} ) Returns the type of {arg} . It is equivalent
170+ to Lua's "type" function, but returns "list",
171171 "dict", "funcref", "buffer", or "window" if
172172 {arg} is a list, dictionary, funcref, buffer,
173- or window, respectively. Examples: >
173+ or window, respectively. Examples: >
174174 :lua l = vim.list()
175175 :lua print(type(l), vim.type(l))
176176 :" list
@@ -190,7 +190,7 @@ Vim evaluation and command execution, and others.
190190 vim.eval({expr} ) Evaluates expression {expr} (see | expression | ),
191191 converts the result to Lua, and returns it.
192192 Vim strings and numbers are directly converted
193- to Lua strings and numbers respectively. Vim
193+ to Lua strings and numbers respectively. Vim
194194 lists and dictionaries are converted to Lua
195195 userdata (see | lua-list | and | lua-dict | ).
196196 Examples: >
@@ -203,16 +203,16 @@ Vim evaluation and command execution, and others.
203203 vim.beep() Beeps.
204204
205205 vim.open({fname} ) Opens a new buffer for file {fname} and
206- returns it. Note that the buffer is not set as
207- current.
206+ returns it. Note that the buffer is not set
207+ as current.
208208
209209 vim.call({name} [, {args} ])
210210 Proxy to call Vim function named {name} with
211211 arguments {args} . Example: >
212212 :lua print(vim.call('has', 'timers'))
213213<
214- vim.fn Proxy to call Vim functions. Proxy methods are
215- created on demand. Example: >
214+ vim.fn Proxy to call Vim functions. Proxy methods
215+ are created on demand. Example: >
216216 :lua print(vim.fn.has('timers'))
217217<
218218 vim.lua_version The Lua version Vim was compiled with, in the
@@ -227,7 +227,7 @@ Vim evaluation and command execution, and others.
227227 *lua-vim-variables*
228228The Vim editor global dictionaries | g: | | w: | | b: | | t: | | v: | can be accessed
229229from Lua conveniently and idiomatically by referencing the `vim .* ` Lua tables
230- described below. In this way you can easily read and modify global Vim script
230+ described below. In this way you can easily read and modify global Vim script
231231variables from Lua.
232232
233233Example: >
@@ -260,8 +260,8 @@ vim.v *vim.v*
2602603. List userdata *lua-list*
261261
262262List userdata represent vim lists, and the interface tries to follow closely
263- Vim's syntax for lists. Since lists are objects, changes in list references in
264- Lua are reflected in Vim and vice-versa. A list "l" has the following
263+ Vim's syntax for lists. Since lists are objects, changes in list references
264+ in Lua are reflected in Vim and vice-versa. A list "l" has the following
265265properties and methods:
266266
267267NOTE: In patch 8.2.1066 array indexes were changed from zero-based to
@@ -274,23 +274,23 @@ Properties
274274 in Vim.
275275 o "l[k]" returns the k-th item in "l"; "l" is one-indexed, as in Lua.
276276 To modify the k-th item, simply do "l[k] = newitem"; in
277- particular, "l[k] = nil" removes the k-th item from "l". Item can
277+ particular, "l[k] = nil" removes the k-th item from "l". Item can
278278 be added to the end of the list by "l[#l + 1] = newitem"
279279 o "l()" returns an iterator for "l".
280280 o "table.insert(l, newitem)" inserts an item at the end of the list.
281281 (only Lua 5.3 and later)
282282 o "table.insert(l, position, newitem)" inserts an item at the
283- specified position. "position" is one-indexed. (only Lua 5.3 and
283+ specified position. "position" is one-indexed. (only Lua 5.3 and
284284 later)
285285 o "table.remove(l, position)" removes an item at the specified
286- position. "position" is one-indexed.
286+ position. "position" is one-indexed.
287287
288288
289289Methods
290290-------
291291 o "l:add(item)" appends "item" to the end of "l".
292292 o "l:insert(item[, pos])" inserts "item" at (optional)
293- position "pos" in the list. The default value for "pos" is 0.
293+ position "pos" in the list. The default value for "pos" is 0.
294294
295295Examples:
296296>
@@ -312,8 +312,8 @@ Examples:
3123124. Dict userdata *lua-dict*
313313
314314Similarly to list userdata, dict userdata represent vim dictionaries; since
315- dictionaries are also objects, references are kept between Lua and Vim. A dict
316- "d" has the following properties:
315+ dictionaries are also objects, references are kept between Lua and Vim. A
316+ dict "d" has the following properties:
317317
318318Properties
319319----------
@@ -340,7 +340,7 @@ Examples:
340340==============================================================================
3413415. Blob userdata *lua-blob*
342342
343- Blob userdata represent vim blobs. A blob "b" has the following properties:
343+ Blob userdata represent vim blobs. A blob "b" has the following properties:
344344
345345Properties
346346----------
@@ -367,7 +367,7 @@ Examples:
367367==============================================================================
3683686. Funcref userdata *lua-funcref*
369369
370- Funcref userdata represent funcref variables in Vim. Funcrefs that were
370+ Funcref userdata represent funcref variables in Vim. Funcrefs that were
371371defined with a "dict" attribute need to be obtained as a dictionary key
372372in order to have "self" properly assigned to the dictionary (see examples
373373below.) A funcref "f" has the following properties:
@@ -408,8 +408,8 @@ can be accessed in Vim scripts. Example:
408408==============================================================================
4094097. Buffer userdata *lua-buffer*
410410
411- Buffer userdata represent vim buffers. A buffer userdata "b" has the following
412- properties and methods:
411+ Buffer userdata represent vim buffers. A buffer userdata "b" has the
412+ following properties and methods:
413413
414414Properties
415415----------
@@ -425,8 +425,8 @@ Properties
425425Methods
426426-------
427427 o "b:insert(newline[, pos])" inserts string "newline" at (optional)
428- position "pos" in the buffer. The default value for "pos" is
429- "#b + 1". If "pos == 0" then "newline" becomes the first line in
428+ position "pos" in the buffer. The default value for "pos" is
429+ "#b + 1". If "pos == 0" then "newline" becomes the first line in
430430 the buffer.
431431 o "b:next()" returns the buffer next to "b" in the buffer list.
432432 o "b:previous()" returns the buffer previous to "b" in the buffer
@@ -460,7 +460,7 @@ Examples:
460460==============================================================================
4614618. Window userdata *lua-window*
462462
463- Window objects represent vim windows. A window userdata "w" has the following
463+ Window objects represent vim windows. A window userdata "w" has the following
464464properties and methods:
465465
466466Properties
@@ -493,18 +493,19 @@ Examples:
4934939. luaeval() Vim function *lua-luaeval* *lua-eval*
494494
495495The (dual) equivalent of "vim.eval" for passing Lua values to Vim is
496- "luaeval". "luaeval" takes an expression string and an optional argument and
497- returns the result of the expression. It is semantically equivalent in Lua to:
496+ "luaeval". "luaeval" takes an expression string and an optional argument and
497+ returns the result of the expression. It is semantically equivalent in Lua
498+ to:
498499>
499500 local chunkheader = "local _A = select(1, ...) return "
500501 function luaeval (expstr, arg)
501502 local chunk = assert(loadstring(chunkheader .. expstr, "luaeval"))
502503 return chunk(arg) -- return typval
503504 end
504505<
505- Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and
506+ Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and
506507list, dict, blob, and funcref userdata are converted to their Vim respective
507- types, while Lua booleans are converted to numbers. An error is thrown if
508+ types, while Lua booleans are converted to numbers. An error is thrown if
508509conversion of any of the remaining Lua types, including userdata other than
509510lists, dicts, blobs, and funcrefs, is attempted.
510511
0 commit comments