Convergent
Convergent

Reputation: 130

How to print the output of a command to a new window in vim

When I execute a command like this:

:g/FIXME/p

It prints the matching lines in the section where I wrote my code. I want to process output of this command more, so I manually select the output text in gvim, open a new split window and paste manually. However, if the output is too big, I cannot do copy&paste easily.

Is there a way to push output of commands into a new window automatically? I.e. what I want to do is something like this:

:g/FIXME/print_to_new_window

Upvotes: 1

Views: 1637

Answers (2)

John Szakmeister
John Szakmeister

Reputation: 47022

You might be interested in using the quickfix window to store your match results. There's some information about this on the vim wiki. The example there shows how to match the current word under the cursor, but you could use something like this:

vim command! -nargs=1 GREP :execute 'vimgrep '.string(<q-args>).' '.expand('%') | :copen | :cc

Then a GREP FIXME would pop-open the matches in a quickfix window, which is great for navigating between the results. Here's what it could look like:

quickfix

This was a result of running :GREP fnamemodify in one of my vim files.

Upvotes: 2

Kent
Kent

Reputation: 195049

if you want to find all matched lines in your buffer and paste to a new window/buffer, you can do this:

:let @a=''|g/FIXME/y A

This line will save all matched (contains FIXME) lines in register a.

Now you can open a window, E.g. :vnew then paste the content from a

"ap

Well if you really want to save the output of a command, you will have to use :redir command, check the help (:h :redir) for details, it is well explained.

Upvotes: 6

Related Questions