Lua api: get first non blank of the line

In vimscrip I can get the first non blank running this command:

:ec match(getline('.'), '\S')+1

How we do that in Lua

I’m afraid your command doesn’t work and depends on the cursor’s position.
You can use vim.api.nvim_buf_get_lines to read the lines of the buffer. The following snippet iterates over the lines and, if it matches the pattern, prints the line number and breaks:

:lua local t = vim.api.nvim_buf_get_lines(0, 0, -1, true); for num, line in ipairs(t) do if line:match("^%s*$") then print(num); break; end end

Depending on the case and performance, you might want to call nvim_buf_get_lines periodically, reading N lines at a time, instead of the whole buffer.