1

My python file:

print('HelloWorld')

After executing the file in terminal history:

HelloWorld
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.

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

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

Please help.

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

2 Answers 2

2

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

:!clear;ls

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.)

0
-2

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:

$ vim $HISTFILE

Or for bash:

$ vim ~/.bash_history
2
  • 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.