From 18dea555873e2617a77749f20f9cfb5abd64904c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Sterle?= Date: Thu, 10 Jun 2021 21:07:11 +0200 Subject: [PATCH] add note about invalid characters for global vars --- README.md | 5 +++-- doc/nvim-lua-guide.txt | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8add734..5d5bdd8 100644 --- a/README.md +++ b/README.md @@ -705,6 +705,8 @@ vim.g.some_global_variable = { print(vim.inspect(vim.g.some_global_variable)) -- { key1 = "value", key2 = 300 } ``` +Some variable names may contain characters that cannot be used for identifiers in Lua. You can still manipulate these variables by using this syntax: `vim.g['my#variable']`. + To delete one of these variables, simply assign `nil` to it: ```lua @@ -750,8 +752,7 @@ end vim.fn.jobstart('ls', { on_stdout = print_stdout }) ``` -Strings with invalid Lua names can be used with `vim.fn[variable]`. -For example, hashes (`#`) are not valid characters for indentifiers in Lua, so autoload functions have to be called with this syntax: +Hashes (`#`) are not valid characters for indentifiers in Lua, so autoload functions have to be called with this syntax: ```lua vim.fn['my#autoload#function']() diff --git a/doc/nvim-lua-guide.txt b/doc/nvim-lua-guide.txt index 51d5c1c..a17f253 100644 --- a/doc/nvim-lua-guide.txt +++ b/doc/nvim-lua-guide.txt @@ -863,6 +863,10 @@ meta-accessors: key2 = 300 } < +Some variable names may contain characters that cannot be used for +identifiers in Lua. You can still manipulate these variables by using +this syntax: `vim.g['my#variable']`. + To delete one of these variables, simply assign `nil` to it: > @@ -914,9 +918,8 @@ converted back and forth from Lua to Vimscript. vim.fn.jobstart('ls', { on_stdout = print_stdout }) < -Strings with invalid Lua names can be used with `vim.fn[variable]`. -For example, hashes (`#`) are not valid characters for indentifiers in -Lua, so autoload functions have to be called with this syntax: +Hashes (`#`) are not valid characters for indentifiers in Lua, so autoload +functions have to be called with this syntax: > vim.fn['my#autoload#function']()