How to redirect output to a new buffer in Vim?

How to redirect output to a new buffer in Vim?

If you find yourself redirecting many commands you may want to wrap up this up in a command: Now you can use the :Redir command to redirect the output to a new buffer. e.g. :Redir scriptnames or :Redir ls. Vim 8 ships with the new execute () function.

How does the new shell command in Vim work?

The new :Shell command works just like :! except that it opens a Vim scratch buffer and prints the command output there. The scratch buffer will be wiped out completely when it’s closed. An example of usage: The idea can be extended by adding shortcut commands for commonly used shell commands.

How to capture the output of running an external command in Vim?

This tip shows how to capture the output from running an external (or shell) command in Vim. Vim has many useful functions which can replace shell commands, such as strftime () or glob (), but sometimes only the shell command will do. See :help function-list for a list of Vim’s built-in functions.

How to load scriptnames into Vim QuickFIX list?

Alternatively Tim Pope’s scriptease.vim provides the :Scriptnames command which will load :scriptnames into the quickfix list and :copen. If you find yourself redirecting many commands you may want to wrap up this up in a command:

How to dump the output of internal Vim command?

This will take normal or system command output and put it in a new tab. Feel free to change the line tabnew to vnew or new etc. ( new and vnew are alternatives to split and vsplit as the output would otherwise be printed in your current file)

Which is the execute function in Vim 8?

Vim 8 ships with the new execute () function. You can use the execute () function to instead of :redir to capture ex-command output. For completeness, I want to present this awesome functions that I collected (stole) from romainl ” redirect the output of a Vim or external command into a scratch buffer function!

How to display the lolcat output in Vim?

In order to have Vim actually interpret these sequences and render those as colors, you can use a plug-in. For example, install plug-in chrisbra/Colorizer and use the command :ColorHighlight after you have the lolcat -f output with the escape sequences in your buffer.

How to redirect ex command output into current buffer or file?

For example, I want to read the contents of all the registers into the current buffer, which in ex mode is shown using :registers. The last command is very useful, since there are lots of options for redirection: to variables, to registers, how to append, further cornucopia.

Do you have to invoke Vim to run bash?

This is the equivalent of opening vim then executing the command :r! ls -la. This should work with any vim command, where the command comes after the -c option. If your goal is simply to get the output into a text file then you don’t need to invoke vim. Bash can do it alone with Now you don’t need to type the ! to quit.

How to insert the result of a command into the text in Vim?

This is accomplished via the :redir command, which allows you to redirect vim’s equivalent of standard output into a variable, file, register, or other target. :redir is sort of painfully inconvenient to use; I would write a function to encapsulate its functionality in a more convenient way, something like