In Neovim 0.5, I’m trying to use the following Lua function for determining the length of a string that contains Unicode characters (such as “áéö”):
:lua utf8.len(string) results in an error message:
E5108: Error executing lua [string ":lua"]:1: attempt to index global 'utf8' (a nil value)
On the other hand, I can use
utf8.len in the official Lua interpreter (by running
lua in the terminal, outside Neovim). I wonder if this is because
utf8 library is not included in Neovim. If that is the case, I’m not sure how to reproduce the behaviour with the tools available in Neovim.
My use case: I have written a function that turns the current buffer line into a reStructuredText or Markdown heading. For instance:
before: after: My heading My heading ==========
For this, I could use
string.len, but it doesn’t reliably tell the length of the line if it contains at least one Unicode character.