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?
3 Answers
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
You can make a command to do just this:
- Open a new split (or tab)
- 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
.
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!
:!
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...:!
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 beforevim
was invoked.TERM
setting?screen
) or alternate-screen (intmux
).