If I have a vim session with two splits, when I execute a :! command, the result is shown in the entire window. Is it possible to have the output shown just on the active split?

  • 2
    No, this is not possible. The output if :! is shown in the command line, of which there is only one, and can only be at the bottom of the screen. The best I can think of is creating a new buffer/:split underneath the current one... – Martin Tournoij Feb 19 '15 at 15:43
  • @Carpetsmoker, For me, the output of :! does not go to the command line. Instead the vim session disappears and the entire terminal window shows the terminal output, including what was printed before vim was invoked. – drs Feb 19 '15 at 15:47
  • 1
    Maybe that's due to the terminal you use and/or the TERM setting? – Martin Tournoij Feb 19 '15 at 15:49
  • This difference has to do with altscreen (in screen) or alternate-screen (in tmux). – tommcdo Feb 22 '15 at 3:31

You can make a command to do just this:

  1. Open a new split (or tab)
  2. Run a command and show the results in that split (or tab)

The command would be something like this:

:Rsplit command

or

:Rtab command

In your .vimrc you can write this:

" execute a command and show its output in a split window
command! -nargs=* -complete=shellcmd Rsplit execute "new | r! <args>"

" execute a command and show its output in a new tab
command! -nargs=* -complete=shellcmd Rtab execute "tabnew | r! <args>"

You can find how to make your own commands with :help :command.

You can use this command :

:new | 0read ! command

This will open up a new split and puts the output of the command in this split (though not in the currently active split as you mentioned).

new - creates new split

read - to get the command output

command - actual command

That won't be possible. You'll have to split your screen with another tool like tmux (IIRC), screen, ...

If you don't need to interact with the program executed, you can however import its results directly in any window (in the vim sense :h windows) you wish with :r!command line. :h :r!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.