Skip to main content

CUU/CUD/CUF/CUB

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

CUU, CUD, CUF, and CUB are CSI sequences that move the cursor by a relative number of positions in a single direction.

Syntax​

CSI Pn A      CUU — Cursor Up
CSI Pn B CUD — Cursor Down
CSI Pn C CUF — Cursor Forward (Right)
CSI Pn D CUB — Cursor Back (Left)
Formal syntax
CUU = 0x1b, "[", [ Pn ], "A" ;
CUD = 0x1b, "[", [ Pn ], "B" ;
CUF = 0x1b, "[", [ Pn ], "C" ;
CUB = 0x1b, "[", [ Pn ], "D" ;
Pn  = digit, { digit } ;                (* default: 1 *)
digit = "0" | "1" | "2" | "3" | "4"
    | "5" | "6" | "7" | "8" | "9" ;

Parameters​

ParameterDescriptionDefault
PnNumber of positions to move1

Description​

Per ECMA-48 §8.3.22 (CUU), §8.3.19 (CUD), §8.3.20 (CUF), §8.3.18 (CUB), these sequences move the active presentation position by Pn positions in the specified direction.

  • CUU (CSI Pn A) — Moves the cursor up by Pn lines. The cursor stops at the top margin of the scrolling region; it does not scroll the display.
  • CUD (CSI Pn B) — Moves the cursor down by Pn lines. The cursor stops at the bottom margin; it does not scroll.
  • CUF (CSI Pn C) — Moves the cursor right by Pn columns. The cursor stops at the right margin; it does not wrap.
  • CUB (CSI Pn D) — Moves the cursor left by Pn columns. The cursor stops at the left margin (column 1); it does not wrap.

If Pn is 0, it is treated as 1 by most terminals (the spec says the default is 1, and a value of 0 is commonly treated the same way). The cursor column (for CUU/CUD) or row (for CUF/CUB) is not changed.

note

These sequences never cause scrolling. Use IND/RI or SU/SD for scroll operations.

Examples​

printf '\e[5A'       # Move up 5 lines
printf '\e[3B' # Move down 3 lines
printf '\e[10C' # Move right 10 columns
printf '\e[2D' # Move left 2 columns
printf '\e[A' # Move up 1 line (default)

Specifications​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓0.1.0Implemented via move_up/move_down/move_forward/move_backward methods
Bobcat✓0.9.0Supported via TerminalCtrl library
contour✓v0.1.0
foot✓YesCUU (A), CUD (B/e), CUF (C/a), CUB (D) handled at csi.c:890-906
Ghostty✓v1.0.0
iTerm2✓YesVT100CSI_CUU/CUD/CUF/CUB tokens parsed and executed via terminalCursorUp/Down/Left/Right
Kitty✓YesCUU/CUD/CUF/CUB (CSI A/B/C/D) fully implemented in vt-parser.c:1193-1203
Konsole✓YesCUU (A), CUD (B), CUF (C), CUB (D) implemented at src/Vt102Emulation.cpp:2124-2127
mintty✓YesCUU (CSI A) at line 3128-3129, CUD (CSI B) at line 3132-3133, CUF (CSI C) at line 3149-3150, CUB (CSI D) at line 3151-3160
mlterm✓rel-2_9_0Implemented at vt_parser.c:5566-5597
PuTTY✓0.45
Rio✓v0.0.3
rxvt-unicode✓1.2
st✓0.1
terminology✓v0.1.0
VT100✓Yes
VTE✓YesFully implemented in vteseq.cc as CUU/CUD/CUF/CUB handlers
WezTerm✓YesCUU (Up), CUD (Down), CUF (Right), CUB (Left) implemented in wezterm-escape-parser/src/csi.rs as Cursor::Up/Down/Right/Left and handled in term/src/terminalstate/mod.rs:2347+
Windows Terminal✓YesImplemented in ITermDispatch.hpp:41-44 as CursorUp, CursorDown, CursorForward, CursorBackward. Constrained by margins per VT510 spec.
xterm✓xterm-406
xterm.js✓2.3.0
Multiplexers
cy✓v0.1.0
GNU Screen✓v.4.2.0
tmux✓1.6CUU (CSI A), CUD (CSI B), CUF (CSI C), CUB (CSI D) all implemented
tuios✓v0.0.15
Zellij✓v0.1.0-alphaCUF also supports alternative form CSI a, CUD also supports alternative form CSI e

See also​