diff runtime/doc/if_lua.txt @ 25503:9947b7e4b319 v8.2.3288

patch 8.2.3288: cannot easily access namespace dictionaries from Lua Commit: https://github.com/vim/vim/commit/9dc4bef897a37a610a28d69cee6d30749db61296 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Aug 4 21:12:52 2021 +0200 patch 8.2.3288: cannot easily access namespace dictionaries from Lua Problem: Cannot easily access namespace dictionaries from Lua. Solution: Add vim.g, vim.b, etc. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8693, from NeoVim)
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Aug 2021 21:15:04 +0200
parents 5c98ea5f5d6e
children d5e9c05b4811
line wrap: on
line diff
--- a/runtime/doc/if_lua.txt
+++ b/runtime/doc/if_lua.txt
@@ -211,6 +211,38 @@ Vim evaluation and command execution, an
 	vim.lua_version		The Lua version Vim was compiled with, in the
 				form {major}.{minor}.{patch}, e.g. "5.1.4".
 
+                                                        *lua-vim-variables*
+The Vim editor global dictionaries |g:| |w:| |b:| |t:| |v:| can be accessed
+from Lua conveniently and idiomatically by referencing the `vim.*` Lua tables
+described below. In this way you can easily read and modify global Vimscript
+variables from Lua.
+
+Example: >
+
+    vim.g.foo = 5     -- Set the g:foo Vimscript variable.
+    print(vim.g.foo)  -- Get and print the g:foo Vimscript variable.
+    vim.g.foo = nil   -- Delete (:unlet) the Vimscript variable.
+
+vim.g                                                   *vim.g*
+        Global (|g:|) editor variables.
+        Key with no value returns `nil`.
+
+vim.b                                                   *vim.b*
+        Buffer-scoped (|b:|) variables for the current buffer.
+        Invalid or unset key returns `nil`.
+
+vim.w                                                   *vim.w*
+        Window-scoped (|w:|) variables for the current window.
+        Invalid or unset key returns `nil`.
+
+vim.t                                                   *vim.t*
+        Tabpage-scoped (|t:|) variables for the current tabpage.
+        Invalid or unset key returns `nil`.
+
+vim.v                                                   *vim.v*
+        |v:| variables.
+        Invalid or unset key returns `nil`.
+
 ==============================================================================
 3. List userdata					*lua-list*