Do you know how to clear ansi term in Emacs so it actually clear the terminal and not change the scroll position?
Yes, in Emacs’ ansi-term
mode, when you try to clear the screen using clear
or Ctrl+L
, it typically just inserts blank lines instead of actually resetting the terminal display. To properly clear the terminal without affecting the scroll position, try one of the following approaches:
tput reset
Run this inside ansi-term
:
shtput reset
This sends a proper terminal reset sequence that should fully clear the screen.
printf
with the ANSI Escape Codeshprintf "\033c"
This sends the ESC c
sequence, which performs a terminal reset.
clear && echo -en "\e[3J"
shclear && echo -en "\e[3J"
The \e[3J
ensures the terminal history is wiped instead of just inserting blank lines.
If you're using Bash or Zsh inside ansi-term
, add this to your .bashrc
or .zshrc
:
shalias cls='clear && echo -en "\e[3J"'
Then, just run cls
inside ansi-term
.
Would you like a more Emacs Lisp-based solution, or does this work for your use case?