Cursor Next Line (CNL)
Move the cursor down `n` rows and to the beginning of the line.
- 0x1B
- ESC
- 0x5B
- [
- ____
- n
- 0x45
- E
The parameter n must be an integer greater than or equal to 1. If n is
less than or equal to 0, adjust n to be 1. If n is omitted, n
defaults to 1.
This sequence always unsets the pending wrap state.
CNL is exactly equivalent to Cursor Down (CUD) followed
by Carriage Return (CR): first move the cursor down
n rows respecting the bottom margin, then carriage
return on that row. CR lands on the left margin,
not unconditionally on column 1: with
origin mode set, or with the cursor
at or to the right of a left margin, the cursor ends up on the left margin.
With no left margin in play the left margin is column 1.
If the current cursor position is at or above the bottom margin, the lowest point the cursor can move to is the bottom margin. If the current cursor position is below the bottom margin, the lowest point the cursor can move to is the final row of the screen. This sequence never triggers scrolling.
Note
CNL differs from a plain line feed (
LF) in two ways: it always returns the cursor to the left margin (like CR + LF), and it accepts a countnso a single sequence can advance multiple lines. Unlike LF, CNL never scrolls the screen when the cursor is at the bottom margin.
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;5H" # row 1, column 5
printf "A"
printf "\033[2E" # CNL down 2 lines, to column 1
printf "X"
|____A_____|
|__________|
|Xc________|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;5H" # row 1, column 5
printf "A"
printf "\033[E" # CNL with default (1)
printf "X"
|____A_____|
|Xc________|
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[1;2r" # scroll region rows 1..2
printf "\033[1;5H"
printf "A"
printf "\033[500E" # CNL way past the bottom margin
printf "X"
|____A_____|
|Xc________|
|__________|
The cursor stops on row 2, the bottom margin, even though row 3 is still part of the screen.
cols=$(tput cols)
printf "\033[${cols}G" # move to last column
printf "A" # set pending wrap state
printf "\033[1E" # CNL cancels pending wrap
printf "X"
|_________A|
|Xc________|