Skip to main content

IRM

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Standard

IRM (Mode 4) is a DECSET/DECRST mode that controls whether newly typed characters insert at the cursor position (shifting existing characters to the right) or replace the character under the cursor.

Syntax​

CSI ? 4 h    DECSET — Enable insert mode
CSI ? 4 l DECRST — Disable insert mode (replace mode)
Formal syntax
DECSET-mode4 = 0x1b, "[", "?", "4", "h" ;
DECRST-mode4 = 0x1b, "[", "?", "4", "l" ;

Description​

Per ECMA-48 §7.2.10, IRM (Insertion Replacement Mode) controls the effect of a received character on the active presentation position.

  • Set (insert mode) — Characters received at the cursor position are inserted. Existing characters from the cursor to the right margin shift right by one position. The character at the right margin is lost (it scrolls off the edge). The cursor advances one position to the right.
  • Reset (replace mode) — Characters received at the cursor position overwrite the character currently at that position. The cursor advances one position to the right. This is the default.
note

IRM is defined as an ANSI standard mode in ECMA-48 and is technically set with CSI 4 h / CSI 4 l (without the ? prefix). However, many terminal emulators accept the private mode form CSI ? 4 h / CSI ? 4 l as well. The ANSI form is more correct per the standard.

Interaction with other features​

  • In insert mode, the ICH (Insert Character) sequence CSI Pn @ inserts blank characters, which is distinct from IRM where printable characters are inserted.
  • Insert mode does not affect characters written via escape sequences; only printable characters received at the cursor position are subject to insertion behavior.

Examples​

printf '\e[4h'       # Enable insert mode (ANSI form)
printf '\e[4l' # Disable insert mode / enable replace mode (ANSI form)
printf '\e[?4h' # Enable insert mode (private mode form)
printf '\e[?4l' # Disable insert mode (private mode form)

Specifications​

SpecificationSection
ECMA-48—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓Yes
Bobcat??Not explicitly configured in Bobcat. TerminalCtrl may support this, but cannot confirm from Bobcat's code.
contour✓v0.3.0.198Implemented as AnsiMode::Insert at primitives.h:606, handled in Terminal.cpp:2251
foot✓Yes
Ghostty✓v1.0.0
iTerm2✓v20260216-nightly
Kitty✓Yes
Konsole✓YesMODE_Insert implemented in Screen class
mintty✓YesImplemented at src/termout.c:2636
mlterm✓rel-0_2_1Present since initial public release
PuTTY✓0.45
Rio✓v0.1.13
rxvt-unicode✓1.2Insert/Replace mode via scr_insert_mode
st✓0.1
terminology✓v0.1.0Uses termstate.insert flag
VT100✓Yes
VTE✓Yes
WezTerm✓Yes
Windows Terminal✓YesIRM_InsertReplaceMode at adaptDispatch.cpp:1762-1764
xterm✓YesANSI insert/replace mode
xterm.js✓5.0.0
Multiplexers
cy✗NoMode tracked but logged as not implemented
GNU Screen✓v.4.2.0Present since at least v.4.0.2 (2005)
tmux✓0.8
tuios✗No
Zellij✓v0.12.0Handled in grid.rs:3016-3120 via CSI 4 h/l

See also​