Vim supports stderr output, which we can redirect to stdout to solve your problem. However, be careful, this function is for debugging purposes only, so it has several edges. Here is a short essay on how you could do this.
First, we will run Vim in silent or batch mode, which is enabled with the -e -s ( :h -s-ex ) flags. We disabled the -n swap files because they would worry if we needed to kill Vim when it got stuck.
Instead of passing Ex commands as command line arguments, we send the script file with -s . Create a hi.vim file with the following contents:
verbose highlight
:verbose requires Vim to display :highlight in stderr. Let's see what we have:
$ vim -n -e -s -S hi.vim
Don't run it yet or you'll be stuck in the darkness of the headless Vim!
Add the command :quit and redirect stderr to stdout:
$ vim -n -e -s -S hi.vim +quit 2>&1
Voila! Now connect this mess to any file or utility in your heart.
There are very detailed articles on this topic, " Vim as a System Interpreter for vimscript .
Finer points: Due to the way Vim interacts with the terminal environment, it cannot write the corresponding final UNIX LF lines in batch mode. Instead, it writes line endings that look like CRLF line endings.
Consider adding a filter to get rid of them:
$ vim -n -e -s -S hi.vim +quit 2>&1 | tr -d '\r' | my-css-util
This answers the general question about how to "redirect the ex command to STDOUT in vim", but this does not necessarily work for your problem :hi due to this restriction caused by the -e -s flags:
'term' and $ TERM are not used.