I want to get the line number by a mark, is it possible to do it in nvim in Lua? I have searched the doc for mark but I cannot find anything useful.


  • 1
    why not using vimscript functions line() and getpos() Commented May 18, 2021 at 8:21

1 Answer 1


You can use :h nvim_buf_get_mark() line this:

local r, c = unpack(vim.api.nvim_buf_get_mark(0, "a"))
print(string.format("row: [%d], col: [%d]", r, c))

The first argument is the reference to the buffer (0 is the current buffer) and the second argument is the name of the mark.

  • 1
    Thank you @statox! Commented May 18, 2021 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.