Show the full output of command :hi in a scratch buffer:
:Redir hi
Show the full output of command :!ls -al in a scratch buffer:
:Redir !ls -al
Show the full output of the previous command in a scratch buffer:
:Redir!
Evaluate the current line with node and show the full output in a scratch buffer:
" current line
console.log(Math.random());
" Ex command
:.Redir !node
" scratch window
0.03987581000754448
Evaluate the current buffer + positional parameters with bash and show the full output in a scratch buffer:
" content of buffer
echo ${1}
echo ${2}
" Ex command
:%Redir !bash -s foo bar
" scratch window
foo
bar
In fact, things can be easier now use the vim command
read. For example,:read !ls -arlhcan exec the external shell commandls -arlhto the buffer in one step directly. If you wanna redirect the command result from the vim ex mode, you can also use the vim command like:put=execute('ls')or:put=execute('buffers'). The variableputis very special in vim. I have used this feature to make my "quickfix" with ripgrep. Here is my vim config -> https://github.com/HCY-ASLEEP/NVIM-Config/blob/main/init.vim.