4

Suppose we did something like:

  1. launch vim with $ vim --clean
  2. execute a shell command :!echo "hello"

After step 1, if we exit Vim the terminal will contain:

$ vim --clean $ 

However after step 2, if we exit Vim the terminal will contain:

$ vim --clean hello Press ENTER or type command to continue $ 

The goal is to prevent any output staying in the terminal after exiting Vim. So after step 2 if we exit vim the terminal should only contain:

$ vim --clean $ 

I tried using :term ++curwin but I want a behaviour similar to running the command with :!cmd and I couldn't really come up with a solution with it (I could be missing something though). I want the whole screen to be used to run the command (not in a split for instance) and after the command execution is done I want to get prompted to press any key to continue. I thought about executing the command in a subshell or something but I am not really sure if that is achievable.

Note: The shell command could involve taking input from the user.

1 Answer 1

2

:w !echo "hello" doesn't put you in "full screen" but it also doesn't use the host shell so it leaves no trace after you quit Vim. See :help :w_c. It is also pretty handy for executing the current line or block in an interpreter, like :.w !ruby.

You could also force Vim to handle the "alternate screen" differently, with something like vim-altscreen. I've had that plugin for years: no complaint whatsoever. I think I heard somewhere that Neovim does the same thing by default, or maybe via an option.

3
  • Thanks a lot! vim-altscreen indeed does exactly what I want :) Commented Aug 5 at 9:10
  • I was wondering though if is it possible to make messages such as Press ENTER or type command to continue or Command terminated appear just after the output of the command being run instead of at the bottom. Commented Aug 6 at 10:53
  • No, we don't have that luxury. Commented Aug 6 at 11:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.