Cursor Backward Tabulation (CBT)

Move the cursor `n` tabs left.

  1. 0x1B
    ESC
  2. 0x5B
    [
  3. ____
    n
  4. 0x5A
    Z

The leftmost valid column for this operation is the first column. If origin mode is enabled, then the leftmost valid column for this operation is the left margin.

Move the cursor left until the cursor position is on a tabstop. If the cursor would move past the leftmost valid column, the cursor remains at the leftmost valid column and the operation completes. Repeat this process n times.

Tabstops are dynamic and can be set with escape sequences such as horizontal tab set (HTS), tab clear (TBC), etc. A terminal emulator may default tabstops at any interval, though an interval of 8 spaces is most common.

Validation

CBT V-1: Left Beyond First Column

printf "\033[?5W" # reset tab stops
printf "\033[10Z"
printf "A"
|Ac________|

CBT V-2: Left Starting After Tab Stop

printf "\033[?5W" # reset tab stops
printf "\033[1;10H"
printf "X"
printf "\033[Z"
printf "A"
|________AX|

CBT V-3: Left Starting on Tabstop

printf "\033[?5W" # reset tab stops
printf "\033[1;9H"
printf "X"
printf "\033[1;9H"
printf "\033[Z"
printf "A"
|A_______X_|

CBT V-4: Left Margin with Origin Mode

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[?5W" # reset tab stops
printf "\033[?6h" # enable origin mode
printf "\033[?69h" # enable left/right margins
printf "\033[3;6s" # scroll region left/right
printf "\033[1;2H" # move cursor in region
printf "X"
printf "\033[Z"
printf "A"
|__AX______|