J.K
J.K

Reputation: 67

clear the output of old external command in VIM

When use ! {cmd} in vim, the output of previous command is not cleared by default. For example, I executed two external command in VIM: ! make and ! gcc. When I type ! gcc, the output of previous command ! make is included:


user@desktop:~$ vim 

make: *** No targets specified and no makefile found.  Stop.

shell returned 2

Press ENTER or type command to continue
gcc: fatal error: no input files
compilation terminated.

shell returned 4

Press ENTER or type command to continue

I want vim to clear these old outputs so that I can view the output of current command clearly, could you offer any advice for this?

Upvotes: 4

Views: 2642

Answers (2)

Tim Abell
Tim Abell

Reputation: 11880

You can wrap vim's execution of all command inside an arbitrary script by setting the shell variable in .vimrc to the path of a script that you can create as you please. Line to add to .vimrc:

set shell=~/.vim/shell-wrapper.sh

Then within the named script you can call clear before running the command originally requested. Minimal contents of ~/.vim/shell-wrapper.sh:

#!/bin/bash
clear
shift # strip the -c that vim adds to bash from arguments to this script
eval $@

You can find my full config here: https://github.com/timabell/dotmatrix (may change over time; last commit at time of writing was https://github.com/timabell/dotmatrix/commit/1098fcbcbcefa67b7a59d7a946cda1730db8ad8b )

Upvotes: 2

Brian Agnew
Brian Agnew

Reputation: 272227

You could run /usr/bin/clear first .e.g.

:!clear && make

Alternatively you could open a new scratch buffer, using this tip.

Upvotes: 4

Related Questions