The following python code uses ansi escape sequences to clear the terminal screen and change the text color to red. It then prints "Hello from Vim."
print ('\033c\033[31m Hello from Vim.')
In Vim I use the command :!python3 %
and everything works as expected. It clears the screen and prints in red. However, when I load the same code into Gvim and use the same command I get :
?c?[31m Hello from Vim.
It neither clears the screen nor prints in red. If from Gvim I split to the terminal with :term
and then enter python3 tester.py
, then code works correctly.
So my question is : Why does the command :!python3 %
not work the same in Gvim as it does in Vim when it comes to ansi escape codes and what can I do to correct that?
Thank you for your assistance.
Edit: Additionally when I run this python script in Gvim :
i = input ('test: ')
and try to use the Backspace key to change the input, I get ^H printed out instead of the cursor backing over the input.
:w !python3 %
on the terminal. Since GVim doesn't have an alternate screen, I guess that's how it can handle output from an external program...