What mechanism allows ViM to temporarily overwrite the entire console?

前端 未结 2 887
谎友^
谎友^ 2021-01-12 01:37

When you enter vim, it \"clears\" the screen. Upon exiting, it \"restores\" the original contents.

I understand one can use \\x1b[2J to clear the consol

2条回答
  •  别那么骄傲
    2021-01-12 02:04

    Regarding the answer by @Keith Thompson — not exactly:

    • vim does not use the screen optimization of ncurses which sends smcup and rmcup automatically. Rather, it is a termcap application. It follows a convention used by most (not all) termcap applications. There are some implementations of vi which do not for instance (on IRIX64 perhaps).
    • as for "most terminals" — actually, xterm look-alikes are a small part of the terminal database (even counting variations, less than 10%). Rephrase that to something like "the most common terminal emulators on Linux.
    • the terminal does not save and restore the screen contents. Instead, it switches between two screens (in xterm's documentation "normal" and "alternate"). In xterm for instance, one can always switch between the two using a menu entry. The xterm FAQ Why doesn't the screen clear when running vi? gives more detail.
    • for better context, note that smcup is an (obscure) abbreviation for set-mode-cursor-positioning, or start cursor-positioning mode. (also cursor-addressing). The r in rmcup means "reset" (and m means "mode"). set/reset have different connotations from save/restore; with the latter the user is led to believe that the values can be stacked up.

提交回复
热议问题