1

The searchcount() gives use something like:

{'exact_match': 1, 'current' : 1, 'incomplete': 0, 'maxcount': 99, 'total': 5}

It is a dictionary, I am trying to do something based on the help:

    local result = vim.fn.searchcount(#{recompute = 1})
    print(result.total)

It gives: E5113: Error while calling lua chunk: Vim:E715: Dictionary needed

1 Answer 1

1

In Lua, the # operator will return the length of a Lua table, the index of the largest element. In this case, {recompute = 1} doesn't have numbered elements, so #{recompute = 1} actually returns 0. (In any case, it will always return an integer number.) You might be mixing up Lua syntax with Vimscript syntax here, since #{...} is valid Vimscript syntax to define a Dictionary.

Just dropping the # should make your example work here.

local result = vim.fn.searchcount({recompute = 1})
print(result.total)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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