Neovim comes with Lua 5.1 built-in and always available. The Lua API provides a powerful, modern interface for configuring and extending Neovim. It consists of three complementary layers:
Vim API
Legacy Vimscript functions and Ex commands accessed via vim.fn and vim.cmd
Nvim API
C-level API functions for remote plugins and GUIs, accessed via vim.api
Lua API
Lua-specific standard library functions available through vim.*
Lua is very simple and consistent. It has three fundamental mechanisms:
Tables: The universal data structure representing both lists and maps
Closures: Every scope (function, module, do block) is a closure and works the same way
Coroutines: Enable cooperative multithreading and generators
Neovim uses Lua 5.1 as the permanent interface. Plugins should target Lua 5.1 for compatibility. While Neovim is built with LuaJIT for performance, code should not assume LuaJIT-specific features like ffi are always available.
Many Neovim Lua functions return (result|nil, error_message|nil) for expected failures:
-- If failure is expected, functions return nil + error messagelocal file, err = io.open('myfile.txt', 'r')if not file then print('Error: ' .. err) returnend-- Use assert() when you can't proceed on failurelocal file = assert(io.open('required.txt', 'r'))
Only false and nil are “falsy” in Lua. Everything else is “truthy”:
if 0 then print('0 is truthy') end -- prints!if '' then print('empty string is truthy') end -- prints!if {} then print('empty table is truthy') end -- prints!