You can use the CmdlineChanged
event to set the highlight:
command -nargs=+ Test echo <q-args>
augroup hl-Test
au!
au CmdlineChanged *
\ if getcmdtype() == ':' && getcmdline()[: 3] == 'Test'
\| let @/ = getcmdline()[4 :]->trim()
\| setl hlsearch
\| redraw
\| endif
augroup end
The getcmdtype()
check ensures it only applies for the :
commandline (and not e.g. /
for search).
The @/
register contains the current search command, which can be set manually; :setl hlsearch
highlights the contents of @/
, and you need to do an explicit redraw
to make it actually highlight.
One thing this doesn't do is scroll to the first instance if it's outside of the current screen; doing that is quite a bit more involved: you need to get the contents of the current view, check if anything matches, if not scroll the view to the first match, and then also restore it after something is typed that no longer matches anything in the view.