I am trying to search for the location of the start and the end of a pair with searchpairpos(). Given an example like this:


And my code like this:

local start_match = vim.api.nvim_call_function('searchpairpos', {"*", "", "*", "zncb"})
local end_match = vim.api.nvim_call_function('searchpairpos', {"*", "", "*", "znc"})

I am only able to search for the start_match, end_match[1] and end_match[2] always return 0 (i.e no match). I guess it is the flag that is causing this issue, but I am not sure how to fix it.

  • I just had a quick look in the vim 8.2 help doc for searchpairpos() and I didn't see anything about a 'z' flag, only 'b,c,n,s,w,W,r,m'. Are you sure there is such a thing as a 'z' flag? (it's possible I missed it, or that's it's a Neovim only feature).
    – mattb
    Commented May 5, 2021 at 16:35
  • 1
    The arguments are patterns, so I would expect you need '\*'
    – D. Ben Knoble
    Commented May 5, 2021 at 17:17
  • In addition to the above comment, searchpairpos() does not work when the start and end have the same pattern. Use searchpos() instead.
    – husB
    Commented May 12, 2021 at 6:40


Your Answer

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

Browse other questions tagged or ask your own question.