Skip to content

EL — Erase in Line

SequenceCSI <n> K
Bytes0x1B 0x5B <n> 0x4B
MnemonicEL
Otty support

Description

Erases part of the current line. Default <n> = 0.

<n>Effect
0Erase from cursor to end of line
1Erase from start of line to cursor
2Erase the whole line

Cursor position is unchanged. Useful for redrawing a status line or progress bar without scrolling.

DECSEL — Selective Erase in Line

CSI ? <n> K (note the ? private marker) is the selective variant: it erases only cells not protected by DECSCA, with the same 0 / 1 / 2 meanings as plain EL. Protected cells on the line are left in place.

bash
printf '\e[1"q'; printf 'KEEP'; printf '\e[0"q'; printf ' wipe'
printf '\r\e[?2K'     # whole line selectively erased — 'KEEP' stays, ' wipe' clears

Example

bash
printf '\r\e[K'      # CR to start of line, erase rest — typical "redraw line" idiom
printf 'progress: %d%%\r\e[K' 42
  • ED
  • DECSCA — mark cells protected from selective erase.
  • CR

Otty