Martín Fixman
Martín Fixman

Reputation: 9585

How can I map a key to execute a program, and show its output in GVim?

On my .gvimrc, I have the following line:

map <f4> :!./%<  

On a source file, I have to press F4 and then enter, but it works correctly, shows the output, and hangs until I press enter again.

If I change it for:

map <f4> :!./%< <CR>

It behaves shows the output, but doesn't wait until I press enter (and so the output becomes impossible to read).

Is there any way to show the output of a program, and hang until I press enter, without having to press enter before of the command, without having to open a separate window?

Upvotes: 0

Views: 441

Answers (3)

DrAl
DrAl

Reputation: 72616

Your second mapping should work correctly. A useful alternative though is to install Dr Chip's RunView plugin. This can be used to have a vertically split window with the script you're editing in one pane and the output from the script in the other pane. Every time you hit the key you've mapped, the output from the script is added to the output pane.

Very useful for debugging scripts.

Upvotes: 0

too much php
too much php

Reputation: 90998

Your second mapping should work correctly. Sometimes this issue is caused by having an extra space at the end of a mapping.

Upvotes: 3

idbrii
idbrii

Reputation: 11916

See :help redir. You can redirect that output to a register and dump it into a buffer.

To give you an idea of how it works, I have this in my vimrc for viewing results from :g/.

"" Puts the last g search command in a new buffer -- clobbers your c buffer
cabbrev what :redir @c<CR>:g//<CR>:redir END<CR>:new<CR>:put! c<CR><CR>

Upvotes: 1

Related Questions