Skip to main content
ansicode

CUU / CUD / CUF / CUB — Move cursor

Move the cursor up / down / right / left by N cells.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[NA (up; B down, C right, D left)
\\033[\033[1A
\\e[\e[1A
ESC [ESC [ N A
hex1b 5b <N> 41

Description

Final byte determines direction: `A`=up (CUU), `B`=down (CUD), `C`=forward/right (CUF), `D`=back/left (CUB). N defaults to 1 if omitted (`\x1b[A` moves up one line). The cursor stops at the edge of the visible region; it does NOT wrap.

Spec citation: ECMA-48 §8.3.22 (CUU) / §8.3.19 (CUD) / §8.3.20 (CUF) / §8.3.18 (CUB)

Parameters

Aup by N
Bdown by N
Cright by N
Dleft by N

Examples

bash
printf 'line1\nline2\033[1A\rCHANGED\033[1B\r\n'
python
import sys; sys.stdout.write('\x1b[2A')
go
fmt.Print("\x1b[2A")
javascript
process.stdout.write('\x1b[2A')
c
printf("\x1b[2A");

Terminal support

xterm
yes
Linux console (fbcon)
yes
macOS Terminal.app
yes
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
yes
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences

In the family cookbook

CSI cookbook · 2. Cursor movement — CUU / CUD / CUF / CUB + CUP + CHA / VPA