VimScript makes a difference between commands and expressions.
Whatever you type in the command-line is a command. Commands can output some text, but they cannot "return" anything, and so they cannot be nested one into another (except string arguments).
On the other hand, expression cannot stand in the command-line alone. E.g. 2+2
is an expression, but in order to print it you have to provide a command, e.g. :echo 2+2
Hence, :cexpr
expects an expression and does not accept commands such as :ls
or :execute
. That's the problem.
A very general approach is :h execute()
function (hence an expression), so
:cexpr execute("ls")
is valid.
However, that's not the best solution. Making use of specialized VimScript functions should be preferred whenever possible. As an example:
cexpr map(getbufinfo({'buflisted': 1}), {_, v -> v.name})