My python file:


After executing the file in terminal history:

Press ENTER or type command to continue

This is fine.

Now, if I then run the file again, it shows the previous history as well.

Press ENTER or type command to continue
Press ENTER or type command to continue

It should only return one 'HelloWorld', and clear the past history.

Please help.

  • @Quasímodo I use gnome-terminal. Dec 31, 2020 at 0:05

2 Answers 2


You need to add a clear before each external command you run. For example, with ls, that would be


It would admitedly be pretty clumsy to type that for each command, so a map can be added in .vimrc. For example,

noremap ! :!clear;

will map ! in normal and visual modes. (That overrides the default ! behavior. If you do not want to override default maps, use one of the unused keys instead.)


There is no one answer. Different shells offer different options for configuring where your history is stored. Generally, the default filename is either .history or .SHELL_NAME_history (for example .bash_history). It’ll be stored in your home directory. You can delete that file, but there’s no guarantee that an open shell process doesn’t have some cached history information waiting to be written. Run the history command to find out the number of the command you want to delete and then issue the following command

$ history -d number

You can also simply edit the history file using vim and delete whatever you want to:


Or for bash:

$ vim ~/.bash_history
  • 2
    You've missed the question. Rahul wants to clear the alternate screen after running each command from inside Vim.
    – Quasímodo
    Dec 30, 2020 at 15:47
  • @Quasímodo yeah exactly. Dec 31, 2020 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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