Commands: Cursor Functions

The coordinates are 1-based, origin is top left. The cursor can move within the entire screen, or in the active Scrolling Region if Origin Mode is enabled.

After writing a character, the cursor advances to the right. If it has reached the end of the row, it stays on the same line, but writing the next character makes it jump to the start of the next line first, scrolling up if needed. If Auto-wrap mode is disabled, the cursor never wraps or scrolls the screen.

*Legend:* Italic letters such as _n_ are ASCII numbers that serve as arguments, separated with a semicolon. If an argument is left out, it's treated as 0 or 1, depending on what makes sense for the command.

Movement

CodeMeaning
\e[nA \\ \e[nB \\ \e[nC \\ \e[nD Move cursor up (`A`), down (`B`), right (`C`), left (`D`)
\e[nF \\ \e[nE Go _n_ lines up (`F`) or down (`E`), start of line
\e[rd \\ \e[cG \\ \e[r;cH Go to absolute position - row (`d`), column (`G`), or both (`H`). Use `\e[H` to go to 1,1.
`\e[6n` Query cursor position. Sent back as `\e[r;cR`.

Save / restore

CodeMeaning
\e[s \\ \e[u Save (`s`) or restore (`u`) cursor position
\e7 \\ \e8 Save (`7`) or restore (`8`) cursor position and attributes

Scrolling Region

CodeMeaning
`\e[a;br` Set scrolling region to rows _a_ through _b_ and go to 1,1. By default, the scrolling region spans the entire screen height. The cursor can leave the region using absolute position commands, unless Origin Mode (see below) is active.
\e[?6h \\ \e[?6l Enable (`h`) or disable (`l`) Origin Mode and go to 1,1. In Origin Mode, all coordinates are relative to the Scrolling Region and the cursor can't leave the region.
\e[nS \\ \e[nT Move contents of the Scrolling Region up (`S`) or down (`T`), pad with empty lines of the current background color. This is similar to what happens when AutoWrap is enabled and some text is printed at the very end of the screen.

Tab stops

CodeMeaning
`\eH` Set tab stop at the current column. There are, by default, tabs every 8 columns.
\e[nI \\ \e[nZ Advance (`I`) or go back (`Z`) _n_ tab stops or end/start of line. ASCII _TAB_ (9) is equivalent to \e[1I
\e[0g \\ \e[3g \\ Clear tab stop at the current column (`0`), or all columns (`3`).

Other options

CodeMeaning
\e[?7h \\ \e[?7l Enable (`h`) or disable (`l`) cursor auto-wrap and screen auto-scroll
\e[?12h \\ \e[?12l Toggle cursor blinking (`h` on, `l` off)
\e[?25h \\ \e[?25l Show (`h`) or hide (`l`) the cursor
\e[?45h \\ \e[?45l Enable (`h`) or disable (`l`) reverse wrap-around (when using "move left" or backspace)