From 6042d3e127f0dc7327842883e543fa00798169c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Sterle?= Date: Wed, 22 Jul 2020 23:27:37 +0200 Subject: [PATCH] Add section on :lua --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index fdfc895..b35426b 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,38 @@ Unlike .vim files, .lua files are not automatically sourced from directories in ### :lua +This command executes a chunk of lua code. + +```vim +:lua require('myluamodule') +``` + +Multi-line scripts are possible using heredoc syntax: + +```vim +echo "Here's a bigger chunk of Lua code" + +lua << EOF +local mod = require('mymodule') +local tbl = {1, 2, 3} + +for k, v in ipairs(tbl) do + mod.method(v) +end + +print(tbl) +EOF +``` + +See also: + +- `:help :lua` +- `:help :lua-heredoc` + +#### Caveats + +You don't get correct syntax highlighting when writing Lua in a .vim file. It might be more convenient to use the `:lua` command as an entry point for requiring external lua files. + ### :luado ### :luafile