CR
CR (Carriage Return) is a C0 control character that moves the cursor to the beginning of the current line without advancing to the next line.
Syntax
CR 0x0D
CR = 0x0d ;
Description
Per ECMA-48 §8.3.15, CR causes the active presentation position to be moved to the line home position of the same line. In standard terminal usage, this means column 1 of the current line.
CR does not erase any characters on the line. Any subsequent output will overwrite existing characters starting from the beginning of the line.
Interaction with LF
In Unix systems, the newline character LF (0x0A) is the standard line terminator. The terminal driver's onlcr setting (on by default) typically translates output LF to CR+LF so that the cursor returns to column 1 when advancing to the next line. When the terminal is in raw mode, LF alone moves down without returning to column 1.
LNM mode
When the Line Feed/New Line Mode (LNM, DECSET mode 20) is set, a received CR causes both a carriage return and a line feed, effectively acting as a "new line" operation.
Examples
printf 'Hello\rWorld' # Overwrites "Hello" with "World"
printf 'ABCDEF\rXY' # Displays "XYCDEF"
Specifications
| Specification | Section |
|---|---|
| ECMA-48 | §8.3.15 |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | Yes | Handler carriage_return() at term/mod.rs:1412 |
| Bobcat | ✓ | 0.9.0 | Basic C0 control, handled in TerminalCtrl library |
| contour | ✓ | v0.1.0 | Implemented in executeControlCode; calls moveCursorToBeginOfLine() |
| foot | ✓ | Yes | Implemented in vt.c:236-238 |
| Ghostty | ✓ | v1.0.0 | Handled in stream.zig:771 as C0.CR (0x0D) |
| iTerm2 | ✓ | Yes | |
| Kitty | ✓ | Yes | |
| Konsole | ✓ | Yes | |
| mintty | ✓ | Yes | Handled in do_ctrl() at src/termout.c:1703 |
| mlterm | ✓ | rel-0_2_1 | |
| PuTTY | ✓ | 0.45 | |
| Rio | ✓ | v0.0.28 | |
| rxvt-unicode | ✓ | rxvt-unicode-1.2 | |
| st | ✓ | 0.6 | |
| terminology | ✓ | v0.1.0 | |
| VT100 | ✓ | Yes | |
| VTE | ✓ | Yes | |
| WezTerm | ✓ | Yes | Handled in performer.rs:402 via ControlCode::CarriageReturn, respects left/right margins |
| Windows Terminal | ✓ | Yes | Handled via CarriageReturn() dispatch in OutputStateMachineEngine.cpp:65-66 |
| xterm | ✓ | Yes | Implemented in charproc.c:3706 via CarriageReturn() |
| xterm.js | ✓ | 2.3.0 | |
| Multiplexers | |||
| cy | ✓ | v0.1.0 | |
| GNU Screen | ✓ | v.4.2.0 | Implemented in Special() function at src/ansi.c:681 |
| tmux | ✓ | 0.8 | Implemented via screen_write_carriagereturn() |
| tuios | ✓ | v0.0.15 | |
| Zellij | ✓ | v0.5.0-beta | |
See also
- LF — Line Feed — Often paired with CR for line advancement
- NEL — Next Line — Combined CR+LF as a single C1 control
- LNM — Line Feed/New Line Mode — Mode that alters CR/LF behavior