Cursor Next Line (CNL)

Move the cursor down `n` rows and to the beginning of the line.

  1. 0x1B
    ESC
  2. 0x5B
    [
  3. ____
    n
  4. 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 move the cursor to column 1 of that row.

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 column 1 (like CR + LF), and it accepts a count n so a single sequence can advance multiple lines. Unlike LF, CNL never scrolls the screen when the cursor is at the bottom margin.

Validation

CNL V-1: Normal Usage

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________|

CNL V-2: Default Parameter

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________|

CNL V-3: Stops at Bottom Margin

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\n\n\n\n" # screen is 4 high
printf "\033[1;3r" # scroll region rows 1..3
printf "\033[1;5H"
printf "A"
printf "\033[500E" # CNL way past the bottom margin
printf "X"
|____A_____|
|__________|
|Xc________|
|__________|

CNL V-4: Pending Wrap is Unset

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________|