Line Feed (LF)

Move the cursor down one line, scrolling if at the bottom margin.

  1. 0x0A
    LF

Hex: 0x0A. ASCII: ^J (Ctrl+J).

Move the cursor down one row. The column is preserved unless linefeed mode (LNM, mode 20) is enabled, in which case LF also performs a carriage return so the cursor ends at column 1 of the next row.

If the cursor is on the bottom row of the scrolling region, LF scrolls the region up by one line. The scrolled-off line is committed to scrollback only when the region starts at the top row and spans every column, and only on a screen that keeps scrollback; the bottom margin plays no part in that decision. The alternate screen keeps no scrollback at all, so lines scrolled off it are always discarded. Outside the scrolling region, the cursor moves down only when it is not already on the last row of the screen.

This sequence always unsets the pending wrap state without performing the deferred wrap.

Note

LF, VT (0x0B) and FF (0x0C) all share a single dispatch, so all three move the cursor down and all three honor LNM. IND (ESC D) produces the same cursor and scroll behavior, but it is the one form that never applies LNM.

Tip

Most modern shells and Unix tooling expect LF alone to end a line and rely on the terminal driver (not LNM) to add the carriage return on output. Leave LNM off unless you are talking to an application that needs the legacy newline behavior.

Validation

LF V-1: Basic Down Move

printf "AB"
printf "\n"
printf "X"
|AB________|
|__X_______|

LF V-2: Scroll at Bottom Margin

rows=$(tput lines)
printf "\033[${rows};1H" # move to bottom-left
printf "A"
printf "\n"
printf "X"
|A_________|
|_X________|

The previous bottom row scrolls up; the new bottom row receives the X after the column is preserved.

LF V-3: With Linefeed Mode (LNM)

printf "\033[20h" # enable LNM
printf "AB"
printf "\n"
printf "X"
printf "\033[20l" # disable LNM
|AB________|
|Xc________|