ViM有什么机制可以暂时覆盖整个控制台? [英] What mechanism allows ViM to temporarily overwrite the entire console?

查看:115
本文介绍了ViM有什么机制可以暂时覆盖整个控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您输入 vim 时,它将清除"屏幕.退出后,它将恢复"原始内容.

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

我知道可以使用\x1b[2J清除控制台并重置光标位置,但这会覆盖终端内容.

I understand one can use \x1b[2J to clear the console and reset the cursor position, but this will overwrite terminal contents.

我认为Vim在幕后使用 ncurses ,在这种情况下,我想更好的问题是这是如何进行的,但是如何完成?

I assume Vim uses ncurses under the hood, in which case I suppose the better question is how ncurses does this, but how is it done?

推荐答案

大多数终端模拟器都可以保存和恢复屏幕内容.

Most terminal emulators are able to save and restore the contents of the screen.

为此的terminfo代码为smcup进入全屏模式,而rmcup退出全屏模式. (较旧的termcap代码为tite.)

The terminfo codes for this are smcup to enter full-screen mode and rmcup to leave it. (The older termcap codes are ti and te.)

如果在terminfo数据库中启用了这些功能,则任何使用ncurses的程序都将在入口处打印smcup字符串,并在出口处打印rmcup字符串.

If these capabilities are enabled in the terminfo database, any program that uses ncurses will print the smcup string on entry, and the rmcup string on exit.

在我当前正在使用的系统上,字符串为(其中\E代表转义字符):

On the system I'm using at the moment, the strings are (with \E representing the Escape character):

smcup: \E7\E[?1;47h
rmcup: \E[2J\E[?1;47l\E8

这将恢复屏幕的先前内容以及光标位置.

This restores the previous contents of the screen as well as the cursor position.

(对于xterm而言)序列的具体含义在此处记录:

The specific meanings of the sequences (for xterm) are documented here:

  • s:
    • \E7保存光标
    • \E[?1;47h应用程序光标键;使用备用屏幕缓冲区
    • smcup:
      • \E7 Save Cursor
      • \E[?1;47h Application Cursor Keys; Use Alternate Screen Buffer
      • \E[2J擦除屏幕
      • \E[?1;47l应用程序光标键;使用普通屏幕缓冲区
      • \E8恢复光标
      • \E[2J Erase screen
      • \E[?1;47l Application Cursor Keys; Use Normal Screen Buffer
      • \E8 Restore Cursor

      (这是假设我正确理解了分号的使用;我对此不是100%肯定.)

      (This assumes I'm understanding the use of the semicolon correctly; I'm not 100% sure of that.)

      这篇关于ViM有什么机制可以暂时覆盖整个控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆