Strovent SystemsSign in
Reference

Alternate screen, mouse and paste modes

The terminal modes full-screen programs switch on: alternate screen, mouse reporting and bracketed paste.

Full-screen programs such as vim, less, htop and tmux change how the terminal behaves while they run. They set modes with ESC [ ? n h and clear them with ESC [ ? n l.

Alternate screen

  • Mode 1049 switches to a second screen with no scrollback, draws the program there, and switches back when the program exits.
  • That is why your earlier output reappears after you quit vim.
  • On the alternate screen the terminal's own scrollback is not used. Scrolling is up to the program (less, vim) or to tmux (its copy mode).

Mouse reporting

When a program turns on mouse mode, taps and drags go to the program, not to the text selection.

1000   press and release
1002   also drag
1003   also plain movement
1006   use a longer format that works on wide screens

If you cannot select text for copying in vim or tmux, mouse mode is on. A common modifier (often Shift) lets you select anyway, or you can turn the program's mouse off (set mouse= in vim, set -g mouse off in tmux).

Bracketed paste

Mode 2004 wraps pasted text in ESC [ 200 ~ and ESC [ 201 ~. A shell or editor can then treat the paste as text, not as typed keys. It prevents surprise commands from running line by line when you paste several lines.

Application cursor keys

Mode 1 makes the arrow keys send ESC O A and so on instead of ESC [ A. Programs turn it on and off themselves.

Stuck modes

If the terminal behaves oddly after a program dies (no echo, mouse letters like ^[[<0;12;5M appear, the screen does not scroll), run reset and press Enter. It resets the terminal modes.

Spotted a mistake? Email [email protected].