You have access to a number of variables in user-defined widgets, in particular
BUFFER which contains the content of the line (or more broadly, the whole buffer, which can be multiline).
How to extract the first word from
BUFFER depends on your definition of words. In this context, the most useful definition is probably based on shell syntax, which is available through the
z parameter expansion flag.
Other sensible definitions are to use whitespace-delimited words, or words consisting of
$WORDCHARS. There are movement commands for that, but while you can call them via the
zle builtin and watch
CURSOR move, it would be easier to manually split the string
In completion widgets, the words of the command for which the completion is taking place are in the